python刷阅读_简单的37行python爬虫刷CSDN博客阅读数

# -*- coding:utf-8 -*-

# 利用爬虫刷CSDN博客阅读数

import requests

from bs4 import BeautifulSoup

# 解析源码

def GetHtmlText(url):

try:

r = requests.get(url, timeout = 30)

r.raise_for_status()

r.encoding = 'utf-8'

return r.text

except:

return ''

# 查找博文地址并进行一次点击

def Find_Click(soup):

Divs = soup.find_all('div', {'class': 'article-item-box csdn-tracking-statistics'})

for Div in Divs:

ClickUrl = Div.find('h4').find('a')['href']

# 点一下

Click = requests.get(ClickUrl, timeout = 30)

def main():

# 博文页数

Pages = int(input('Please enter the number of blog pages:'))

for Page in range(1, Pages + 1):

print('Page=', Page)

# 博客地址,这里是我的CSDN博客地址

url = 'https://blog.csdn.net/qq_44621510/article/list/' + str(Page)

html = GetHtmlText(url)

soup = BeautifulSoup(html, 'html.parser')

Find_Click(soup)

if __name__ == '__main__':

main()

运行成功后,输入你的博客页数,程序就会自动把所有的博客遍历一遍,

即每个博客阅读数加1.

待优化:

1,运行一次程序,每个博客阅读数只加1,然后运行结束,再想增加需要再次运行。

2,点击速度较慢,大概15秒一页(20个)

3,每次重新运行都要输入page数。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值