40行代码换1000文章阅读量?

前言

  1. 这篇文章虽说可以教你刷文章阅读量,但是仅供学习测试使用。
  2. 不要拿来恶意刷CSDN访问量,账号出问题概不负责。

代码

话不多说直接上Python代码,代码很简单,注释都写在了代码里。

# coding:utf-8
import re
import time

import requests

payload = ""
# 请求头
headers = {
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate, br",
    "Accept-Language": "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3",
    "Cookie": "l=AurqcPuigwQdnQv7WvAfCoR1OlrRQW7h; isg=BHp6mNB79CHqYXpVEiRteXyyyKNcg8YEwjgLqoRvCI3ddxqxbLtOFUBGwwOrZ3ad; thw=cn; cna=VsJQERAypn0CATrXFEIahcz8; t=0eed37629fe7ef5ec0b8ecb6cd3a3577; tracknick=tb830309_22; _cc_=UtASsssmfA%3D%3D; tg=0; ubn=p; ucn=unzbyun; x=e%3D1%26p%3D*%26s%3D0%26c%3D0%26f%3D0%26g%3D0%26t%3D0%26__ll%3D-1%26_ato%3D0; miid=981798063989731689; hng=CN%7Czh-CN%7CCNY%7C156; um=0712F33290AB8A6D01951C8161A2DF2CDC7C5278664EE3E02F8F6195B27229B88A7470FD7B89F7FACD43AD3E795C914CC2A8BEB1FA88729A3A74257D8EE4FBBC; enc=1UeyOeN0l7Fkx0yPu7l6BuiPkT%2BdSxE0EqUM26jcSMdi1LtYaZbjQCMj5dKU3P0qfGwJn8QqYXc6oJugH%2FhFRA%3D%3D; ali_ab=58.215.20.66.1516409089271.6; mt=ci%3D-1_1; cookie2=104f8fc9c13eb24c296768a50cabdd6e; _tb_token_=ee7e1e1e7dbe7; v=0",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64;` rv:47.0) Gecko/20100101 Firefox/47.0"
}

# 获得文章列表urls
def getUrls(url):

    resp = requests.request("GET", url, data=payload, headers=headers)
    resp.encoding=resp.apparent_encoding
    html_source = resp.text
    # 正则表达式,取出主页中的博客链接
    urls = re.findall("https://[^>\";\']*\d",html_source)
    new_urls=[]
    for url in urls:
        if 'details' in url:
            if url not in new_urls:
                new_urls.append(url)
    return new_urls

# 通过博客首页url获取所有文章url集合(这里换上自己博客主页)
urls = getUrls("https://blog.csdn.net/M283592338")
i=0
while True:
    # 遍历集合并向该url发送get请求
    for url in urls:
        requests.request("GET", url, data=payload, headers=headers)
        print(url, "request--OK!")
        print ("第", i, "次访问")
        i+=1
        # 访问后休息一段时间,不要连续发起求,某些网站短时间内多次请求记为1次
        time.sleep(6)
    # 请求完所有文章继续发起下一轮请求
    time.sleep(6)

写在最后

这个代码刷1000次貌似就会被限流,所以大家控制好自己的欲望。

©️2020 CSDN 皮肤主题: 黑客帝国 设计师:上身试试 返回首页