给自己刷阅读量

import requests
from bs4 import BeautifulSoup
import time
#替换头部信息(网上找的) 不然进不去
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}
count = 1
q_url = input("请输入文章url:")
url = f"{q_url}"
#url ="https://www.cnblogs.com/zhangzhang001/p/16655733.html"
respon = requests.get(url,headers=headers)
respon.encoding = 'utf-8'
print(respon.status_code)
code = BeautifulSoup(respon.text,"html.parser")
#print(code.title)
#寻找url存在的a标签
html = code.find("h1",class_="postTitle").find_all("a")
#print(html)
while(1):
    for a in html:
        blog_url = a.get('href')#博客地址在href中
        #print(blog_url)
        #下面的就是模拟点击进去
    resp = requests.get(blog_url, headers=headers)
    resp.encoding = 'utf-8'
    code_blog = BeautifulSoup(resp.text, "html.parser")
    print(code_blog.title)
    print('成功' + str(count) + '次')
    count += 1
    time.sleep(5)
    #爬取数据适合本博客,如果你的博客与我文章内容上有差异是运行不起来的。

 此脚本无法刷出效果,想要刷出效果需要用到代理IP池。。。

posted @ 2022-09-14 21:37  张小张#  阅读(99)  评论(0编辑  收藏  举报