import requests
import time
from lxml import etree
import pymongo
import re
class CSDN():
def __init__(self):
url = 'https://blog.csdn.net/'
self.headers = {
'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
'accept-encoding': 'gzip, deflate, br',
'accept-language': 'zh-CN,zh;q=0.9',
'cache-control': 'max-age=0',
'cookie': #填自己的,
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36',
'x-tingyun-id': 'wl4EtIR_7Is;r=364167216'
}
self.lst = []
self.num = 0
content = requests.get(url, headers=self.headers).text
爬取CSDN的瀑布流
最新推荐文章于 2022-05-16 11:54:18 发布
本文介绍如何改造Scrapy项目,改用requests库来爬取CSDN的瀑布流内容。由于瀑布流数据是通过JS生成的JSON接口,因此主要涉及如何获取并解析这个接口,抓取到的数据最终将存储到数据库中。注意,实际操作时需要提供有效的cookie。
摘要由CSDN通过智能技术生成