爬取知乎热榜笔记

学习自网易云课堂的爬虫直播

import re
import requests
from lxml import etree
content_re=re.compile('"titleArea":{"text":"(.*?)"},"excerptArea":{"text":"(.*?)"},"imageArea":{"url":"(.*?)"}')
headers={
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
}

def get_hot(url):
    html=requests.get(url,headers=headers)
    soup=etree.HTML(html.text)
    hots=soup.xpath('//*[@id="root"]/div/main/div/a/div[2]/div[1]/text()')
    
    '''for h in hots:
        print(h)'''
    contents=content_re.findall(html.text)
    for c in contents:
        print('标题:',c[0])
        print('内容:',c[1])
        print('图片地址:',c[2].replace(r'\u002F','\\'))
    #print('https:\\pic4.zhimg.com\80\v2-bec82a1f6d71687ad0e5261a01d3fc77_1440w.jpg'.encode().decode("'unicode_escape','ignore'"))
if __name__ == '__main__':
    url='https://www.zhihu.com/billboard'
    get_hot(url)
	
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于selenium对知乎热搜榜进行爬虫并可视化python源码+项目说明+数据集.zip ## 1.Requirements: 打开文件夹, 在地址栏输入 %comspec% 并按回车 ![image-20200613122022518](https://user-images.githubusercontent.com/60550888/84560905-9bd0f700-ad7a-11ea-97df-b1fdab857edc.png) 这样可以在当前目录下打开cmd ![image-20200613122113348](https://user-images.githubusercontent.com/60550888/84560912-b99e5c00-ad7a-11ea-81a1-ceb35c124324.png) 命令行输入`pip install -r requirements.txt` 并回车,安装所需要的库 ![image-20200613123008622](https://user-images.githubusercontent.com/60550888/84560929-ed798180-ad7a-11ea-89c5-ab60efcf118f.png) 之后打开 **zhihu_crawler.py**, 将webdriver设置成自己的绝对地址,并保存 ![image-20200613123234436](https://user-images.githubusercontent.com/60550888/84560942-113cc780-ad7b-11ea-9b67-11e76e6f3331.png) 然后打开**selenium_login.py**, 进行同样的操作,并输入你的知乎的账号和密码,并保存 ![image-20200613123427592](https://user-images.githubusercontent.com/60550888/84560954-26b1f180-ad7b-11ea-9f7c-5d1afffe7890.png) 最后打开 **main.py** , 进行同样的操作,并保存 ......
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值