+
80
-

python爬虫如何突破 CloudFlare 五秒盾防御?

python爬虫如何突破 CloudFlare 五秒盾防御?


网友回复

+
0
-

使用pip install cfscrape安装cloudflare-scrape

同时确认本地是否安装node.js开发环境,如果没有,需要安装配置nodejs开发环境。

使用实例

处理 get 请求的 CloudFlare
import cfscrape
# 实例化一个create_scraper对象
scraper = cfscrape.create_scraper()
# 请求报错,可以加上时延
# scraper = cfscrape.create_scraper(delay = 10)
# 获取网页源代码
web_data = scraper.get("https://example.com/").content
print(web_data)

处理 post 请求的 CloudFlare

# import cfscrape
# 实例化一个create_scraper对象
scraper = cfscrape.create_scraper()
# 获取真实网页源代码
web_data = scraper.post("http://example.com").content
print(web_data)

我知道答案,我要回答