import requests
import re
url = "https://s.weibo.com/top/summary?Refer=top_hot&topnav=1&wvr=6"
headers = {
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:94.0) Gecko/20100101 Firefox/94.0"
, "Cookie": "UOR=www.huiyi8.com,widget.weibo.com,www.huiyi8.com; SINAGLOBAL=2637637648891.33.1630215838590; ULV=1630215838591:1:1:1:2637637648891.33.1630215838590:; SUB=_2AkMW_nogf8NxqwJRmfgVzG7mbIhyzA_EieKgoov7JRMxHRl-yT8XqkBYtRB6PX5UwoLid6hE2_VZ1IleEqWgAAIWUIyf; SUBP=0033WrSXqPxfM72-Ws9jqgMF55529P9D9W5j30oGSN6ZPAI5Z2TfrawQ"
}
# 3获取网页数据
r = requests.get(url, headers=headers)
obj=re.compile(r'<td class="td-01 ranktop">(?P<rank>\d+)</td>.*?<td class="td-02">.*?<a href="(?P<href>.*?)" target="_blank">(?P<resou>.*?)</a>',re.S)
result=obj.finditer(r.text)
for i in result:
print(i.group("resou"))
用的是正则表达式匹配热搜榜,所以功能有限,只能活的一些普通的数据