首页 > 其他 > 详细

微博热搜前十

时间:2020-03-21 19:42:02      阅读:49      评论:0      收藏:0      [点我收藏+]

import requests
from lxml import etree
url="https://s.weibo.com/top/summary?Refer=top_hot&topnav=1&wvr=6"#网址
#模拟浏览器
header={‘User-Agent‘:‘Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36‘}
#主函数
def main():
html=etree.HTML(requests.get(url,headers=header).text)#获取html页面
rank=html.xpath(‘//td[@class="td-01 ranktop"]/text()‘)
affair=html.xpath(‘//td[@class="td-02"]/a/text()‘)
view = html.xpath(‘//td[@class="td-02"]/span/text()‘)
affair=affair[1:]
print(‘ 微博热搜前十 ‘)
for i in range(0, 10):
print("{0:<10}\t{1:{3}<30}\t{2:{3}>20}".format(rank[i],affair[i],view[i],chr(12288)))
main()

技术分享图片

 

微博热搜前十

原文:https://www.cnblogs.com/cjh159/p/12541522.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!