python脚本借助代理刷浏览量

前言

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

python代码

这里我用的是西祠代理地址

import requests
import re
import user_agent#这个库是改变user-agent头的
import threading
import 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("<td>(\d+\.\d+\.\d+\.\d+)</td>",html,re.S)
        ports=re.findall("<td>(\d+)</td>",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库进行利用,实现这一功能

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值