博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python脚本借助代理刷浏览量
阅读量:3959 次
发布时间:2019-05-24

本文共 1413 字,大约阅读时间需要 4 分钟。

前言

我们写了一些文章,如何去刷他们的浏览量呢,我的思路是利用代理服务器,如果浏览量是计算ip的个数,只能利用代理服务器

python代码

这里我用的是西祠代理

import requestsimport reimport user_agent#这个库是改变user-agent头的import threadingimport time#print(user_agent.generate_user_agent())url="http://class184.cn/index.php/2020/01/08/webstudy/"#这里是你想要刷流浪数量的网址,如果需要替换即可def res (ip):    proxies = {
"http": "http://" + ip[0] + ":" + ip[1], "https": "http://" + ip[0] + ":" + ip[1], } try: res = requests.get("http://www.baidu.com", proxies=proxies, timeout=3) res1 = requests.get(url, proxies=proxies, timeout=3)#这个网址是我写的一个博客地址 print(ip, "能够使用") except Exception as e: pass #print(ip, "不能使用")def getip(i): headers = {
"User-Agent": ""+user_agent.generate_user_agent()+"" } url="https://www.xicidaili.com/nn/{}".format(i) response=requests.get(url=url,headers=headers) #print(response.text) html=response.text ips=re.findall("(\d+\.\d+\.\d+\.\d+)",html,re.S) ports=re.findall("(\d+)",html,re.S) print(ips) print(ports) for ip in zip(ips,ports): threading.Thread(target=res, args=(ip,)).start() #print(ip)for i in range(1,3000): getip(i) time.sleep(5)#如果过快的爬取代理网站会被禁ip,这里我已经被禁了很多次-_-

这是我执行脚本后的结果,不算正常访问的,大概刷了200多次吧,因为我刚开始去爬代理网页的时候,爬的太猛了,被禁ip了,一页大概有四五个能用吧…

我们可以将爬取网站封装成一个方法,多找几个代理网站,用正则将他们匹配下来,然后用requests库进行利用,实现这一功能

转载地址:http://iuhzi.baihongyu.com/

你可能感兴趣的文章