Python3 爬虫 之 增加csdn访问量 源代码(直接拿去就能用)

版权声明:欢迎转载,如果转载,请注明转载地址,谢谢你啦!觉得文章不错的话右上角点个赞再走呀! https://blog.csdn.net/qq_40763929/article/details/87082228
#需要Pycharm,然后安装相应的库,才能运行此代码,具体要安装的库,你看运行报错就行了

import re
import time
import random
import requests
import urllib.request
from bs4 import BeautifulSoup
host = "https://blog.csdn.net"
IPRegular = r"(([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5]).){3}([1-9]?\d|1\d{2}|2[0-4]\d|25[0-5])"
firefoxHead = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0"}
codes = ["82770410", "82825833"]
url = "https://blog.csdn.net/qq_40763929/article/details/86772474"#在这里添加你所需要增加访问量的文章地址
def parseIPList(url="http://www.xicidaili.com/"):
    IPs = []
    request = urllib.request.Request(url, headers=firefoxHead)
    response = urllib.request.urlopen(request)
    soup = BeautifulSoup(response, 'html.parser')
    tds = soup.find_all("td")
    for td in tds:
        string = str(td.string)
        if re.search(IPRegular, string):
            IPs.append(string)
    return IPs
def PV(code):
    s = requests.Session()
    s.headers = firefoxHead
    count = 0
    while True:
        count += 1
        print("正在进行第{}次访问\t".format(count), end="\t")
        IPs = parseIPList()
        s.proxies = {"http": "{}:8080".format(IPs[random.randint(0, 40)])}
        s.get(host)
        r = s.get(url.format(code))
        html = r.text
        soup = BeautifulSoup(html, "html.parser")
        spans = soup.find_all("span")
        print(spans[2].string)
        time.sleep(random.randint(60, 75))
def main():
    PV(codes[0])
if __name__ == "__main__":
    main()

猜你喜欢

转载自blog.csdn.net/qq_40763929/article/details/87082228