zoukankan      html  css  js  c++  java
  • 老李性能测试分享:可以没事代理刷榜赚外快了,poptest这是让你快速致富啊

    老李性能测试分享:可以没事代理刷榜赚外快了,poptest这是让你快速致富啊

     

             最近学员不断面试,不时听到令人惊喜的消息,类似应届专科毕业生获得7k月薪,小美女应聘月薪11k等等,看到学员开心的笑容令人开心。在POPTEST学习很辛苦,每天学员起早贪黑,回家10点正常,11,12点回家不稀奇,学员也有自己的生活,有的时候会让我去给他们刷榜,其实学员在前面的学习中已经有了基础(我在过去的文章里“测试开发Python培训:实现屌丝的黄色图片收藏愿望(小插曲)” ),可以实现”性能测试中如何实现模拟不同的ip访问“这样的脚本,所以我这里通过爬虫技术爬下代理ip,然后采用多进程的方法来访问www.poptest.cn,实现利用代理ip地址访问网站,间接说明如何帮学员刷榜,~_~!!!!!,脚本如下:

    # coding: utf-8

    __author__ = 'zzg'

     

    import requests

    from bs4 import BeautifulSoup

    import multiprocessing

    import time

     

    def getProxyIp():

        proxy = []

        for i in range(1,12):

            print i

            header= {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '

                                                   'AppleWebKit/537.36 (KHTML, like Gecko) '

                                                   'Ubuntu Chromium/44.0.2403.89 '

                                                   'Chrome/44.0.2403.89 '

                                                   'Safari/537.36'}

            r = requests.get('http://www.xicidaili.com/nt/{0}'.format(i),headers= header)

     

            html = r.text

            soup = BeautifulSoup(html)

            table = soup.find('table', attrs={'id': 'ip_list'})

            tr = table.find_all('tr')[1:]

            #解析得到代理ip的地址,端口,和类型

            for item in tr:

                tds =  item.find_all('td')

                temp_dict = {}

                kind = tds[6].get_text().lower()

                if 'http' in kind:

                    temp_dict['http'] = "http://{0}:{1}".format(tds[2].get_text(), tds[3].get_text())

                if 'https' in kind:

                    temp_dict['https'] = "https://{0}:{1}".format(tds[2].get_text(), tds[3].get_text())

     

                proxy.append(temp_dict)

        return proxy

     

    def brash(proxy_dict):

        header= {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) '

                                               'AppleWebKit/537.36 (KHTML, like Gecko) '

                                               'Ubuntu Chromium/44.0.2403.89 '

                                               'Chrome/44.0.2403.89 '

                                               'Safari/537.36'}

        try:

            r=requests.get("http://WWW.POPTEST.CN", headers=header,proxies=proxy_dict,timeout=1)

        except Exception, e:

            print "failed"

        else:

            print "successful"

        time.sleep(0.5)

        return None

     

    if __name__ == '__main__':

        i = 0

        t = 0

        final = input() # 输入数字代表要获取多少次代理ip

        while t< final:

            t += 1

            proxies = getProxyIp() # 获取代理ip网站上的前12页的ip

            # 为了爬取的代理ip不浪费循环5次使得第一次的不能访问的ip尽可能利用

            for i in range(5):

                i += 1

                # 多进程代码开了32个进程

                pool = multiprocessing.Pool(processes=32)

                results = []

                for i in range(len(proxies)):

                    results.append(pool.apply_async(brash,(proxies[i],)))

                for i in range(len(proxies)):

                    results[i].get()

                pool.close()

                pool.join()

            i = 0

    代码说明:利用python的requests和Beautifulsoup库从网站上的代理ip爬下来,再把proxy设置为爬取下来的ip地址,再用多进程技术加快刷访问的速度。同学们手下留情啊,poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标。这么访问会让网站受不了啊。李爱然,王远兵,鸟人们不要骂我啊。。。。。。。。。。。。。

  • 相关阅读:
    Parameter Binding in ASP.NET Web API
    Which HTTP methods match up to which CRUD methods?
    ErrorHandling in asp.net web api
    HttpStatusCode
    Autofac Getting Started(默认的构造函数注入)
    Autofac Controlling Scope and Lifetime
    luvit 被忽视的lua 高性能框架(仿nodejs)
    undefined与null的区别
    VsCode中使用Emmet神器快速编写HTML代码
    字符串匹配---KMP算法
  • 原文地址:https://www.cnblogs.com/poptest/p/4929770.html
Copyright © 2011-2022 走看看