码迷,mamicode.com
首页 > 其他好文 > 详细

获取微博前十热搜

时间:2020-03-21 18:07:45      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:pat   gen   pre   lxml   safari   use   png   pytho   rank   

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)
    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()‘)
    top=affair[0]
    affair=affair[1:11]
    print(‘{0:<10}\t{1:<40}‘.format("top",top))
    for i in range(0, len(affair)):
        print("{0:<10}\t{1:{3}<30}\t{2:{3}>20}".format(rank[i],affair[i],view[i],chr(12288)))
main()

  

技术图片

获取微博前十热搜

标签:pat   gen   pre   lxml   safari   use   png   pytho   rank   

原文地址:https://www.cnblogs.com/linbei1/p/12540313.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!