Python网络爬虫案例:知乎Live
涉及的技术包括以下3种:
爬取网页:解析Ajax动态加载地址解析网页:提取JSON数据存储数据:存储至MongoDB数据库
1.项目描述
知乎Live的URL为:/lives
首先爬取Live的第一页:
#!/usr/bin/env python# -*- coding: utf-8 -*-"""@File : GetLive.py@Author: Xinzhe.Pang@Date : /7/18 22:32@Desc : """import requestsdef scrapy(link):headers = {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36}r = requests.get(link, headers=headers)return (r.text)link = "/lives/homefeed?includes=live"html = scrapy(link)print(html)
除了首页,我们还尝试获取其他页的Live信息。首先,尝试是