1 Cloudflare 5秒盾是什么

Cloudflare是一个流行的服务,用于保护网站免受DDoS攻击和其他安全威胁。然而,这种保护服务有时会给合法用户带来问题,例如出现难以解决的验证码人机验证。

最典型和常见的,就是请求的时候会出现 Just a moment...

Checking your browser before accessing xxx.
This process is automatic. Your browser will redirect to your requested content shortly.
Please allow up to 5 seconds…

打开网易新闻 查看精彩图片

2越过免费版Cloudflare 的办法

免费版的,用cloudscraper就能简单越过。

import cloudscraper
scraper = cloudscraper.create_scraper()
resp = scraper.get('目标网站').text

打开网易新闻 查看精彩图片

3付费版的Cloudflare 越过法

付费版的,上面的方法会返回

Detected a Cloudflare version 2 (aptcha challengeeature is not available in the operce (free) version

但是,上述插件是没有付费渠道。

要解决这个问题,有两个常用的办法,

  1. 使用 undetected_chromedriver
  2. 但是该方法很难受,很占内存。
  3. 使用FlareSolverr,它封装了 undetected_chromedriver,通过代理的方式返回正常页面的cookie和原始页面数据。简单易用,而且有效。它是个开源的项目,有兴趣的可以去研究一下它的源码(github)

4FlareSolverr 使用方法

docker cli的命令行如下:

docker run -d --name=flaresolverr -p 8191:8191 -e LOG_LEVEL=info --restart unless-stopped ghcr.io/flaresolverr/flaresolverr:latest

打开网易新闻 查看精彩图片

其他版本的,自行在docker hub上寻找。

python的使用办法

打开网易新闻 查看精彩图片

获取到的数据就不再是5秒盾的内容了

打开网易新闻 查看精彩图片

学无止境