zoukankan      html  css  js  c++  java
  • Python3 爬虫 之 增加csdn访问量 源代码(直接拿去就能用)

    #需要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|1d{2}|2[0-4]d|25[0-5]).){3}([1-9]?d|1d{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("正在进行第{}次访问	".format(count), end="	")
            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()
    
  • 相关阅读:
    分享50个漂亮的设计师个人作品集网站案例
    Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结
    ajax异步请求
    angularJS(6)
    angularJS(5)
    PHP实现RTX发送消息提醒
    ajax异步请求
    angularJS(4)
    angularJS(3)
    jsPanel插件Option总结
  • 原文地址:https://www.cnblogs.com/Romantic-Chopin/p/12451126.html
Copyright © 2011-2022 走看看