获取知乎热点前十

Posted c---y

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了获取知乎热点前十相关的知识,希望对你有一定的参考价值。

import requests
from bs4 import BeautifulSoup
import time
import os
import urllib

#需要爬取的目标网页
link=‘https://www.zhihu.com/hot‘

#对网页进行解析
soup=BeautifulSoup(r.text,‘lxml‘)

#获取到热榜对应的那部分内容
title_list=soup.find_all(‘section‘,class_=‘HotItem‘)

#循环爬取相关内容
for each in title_list[0:10]:
    index=each.find(‘div‘,class_=‘HotItem-rank‘).text#排名
    title=each.find(‘h2‘,class_=‘HotItem-title‘).text#标题
    number=each.find(‘div‘,class_="HotItem-metrics").text[0:-3]#热度
    print(index,title,number)

 

 

 技术图片

以上是关于获取知乎热点前十的主要内容,如果未能解决你的问题,请参考以下文章

作业十代码

获取网易全站热点前十及其点击量

scrapy模拟登陆知乎--抓取热点话题

Scrapy 模拟登陆知乎--抓取热点话题

利用scrapy模拟登录知乎

Golang知乎xx API:收藏回答