Python爬虫学习--WIN10下定时获取CSDN个人的访问量并保存到文件中2018/04/30

CSDN的源码又更新了,现在的最新版本的代码如下:

import requests,time
from bs4 import BeautifulSoup
res = requests.get('http://blog.csdn.net/sayWhat_sayHello?ref=toolbar')
res.encoding = 'utf-8'
soup = BeautifulSoup(res.text,"html.parser")
class_tag = soup.find(class_="grade-box clearfix")
message_tag = class_tag.contents[3].contents[3]["title"]
time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
f = open('Views.txt','a')
f.write( "访问:"+ message_tag+"次 ")
f.write("获取时间:"+time+"\n")
f.close()
print( "访问:"+ message_tag+"次 "+("获取时间:"+time+"\n"))

具体分析查看往期。

猜你喜欢

转载自blog.csdn.net/saywhat_sayhello/article/details/80149256