爬取自己博客的访问量,积分,排名的信息
学python不久,前一个月看见了一篇爬取csdn的文章,一直想自己试试,今天总算完成了一个比较low的版本了吧
from requests import *
import os
import time
from bs4 import BeautifulSoup
try:
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.103 Safari/537.36'}
#headers伪装成浏览器访问
url = "http://blog.csdn.net/bestsort"
r = get(url = url,headers = headers,timeout = 3)
if r.status_code != 200:
print("爬取失败\n")
else:
for Time in range(5,0,-1):
#这里因为不知道怎么调整光标位置和删除,所以直接用cls清屏然后重新打印了
html = r.text
soup = Beautifu