爬取知乎热度

import requests
import re
import pandas as pd
headers = { 'User-Agent': ''}
response = requests.get('https://tophub.today/n/mproPpoq6O',headers=headers)
html=response.text
#print(html)
#请求网页
urls = re.findall('<a href=.*? target="_blank" .*?>(.*?)</a>',html)[4:14]
redu = re.findall('<td>(.*?)</td>',html)[1:11]
#解析网页与抓取信息
dict = {'题目':urls,'热度值':redu}
a = pd.DataFrame(dict)
print(a)
#完成创建

posted @ 2020-03-21 20:49  白。。  阅读(203)  评论(0)    收藏  举报