项目思路:
1、目标:CSDN博客提升访问量,增加每一篇文章的阅读数量。
2、规则:只要用浏览器访问了CSDN博客的某一篇文章,博客访问量就会提升。
3、解决思路:
a. 使用python,调用webbrowser模块,该模块可以调用电脑中的浏览器去访问某一个url。
b. 使用爬虫技术,自动获取博客中所有文章的url。
c. 使用程序循环结构,迭代每一个文章的url,用浏览器访问。
d. 为了更加真实模拟用户操作,也为了减小电脑压力,使用time模块,设置一个浏览器打开url的间距时间。
e. 考虑到浏览器打开多个网页占用过多内存,使用os模块调执行dos命令在一定条件下关闭浏览器。
项目代码如下:
# coding=utf-8
import webbrowser,time,os,requests,re,random
def web(website):
html=requests.get(website)
text=html.text
# print(text)
reg=website+'article/details/\d+'
urls=re.findall(reg,text)
#print(urls)
url=[]
for i in urls:
if i not in url:
url.append(i)
#print(url)
count=1
while 1:
for i in url:
time.sleep(random.randint(5,10))
webbrowser.open(i)
print("刷博客第%d次!博客网址:%s"%(count,i))
count+=1
if count%11==0:
os.system("taskkill /F /IM chrome*")
web("https://blog.csdn.net/sisure_shen/")