Python and CloudFlare issue



我在尝试向https://1stkissmanga发出请求时遇到了瓶颈。io/由于CloudFlare保护。我准备了header和cookie(我从Firefox中读取),但仍然没有成功。奇怪的是,我可以得到这个网站正确与wget。这是我不明白的问题- wget没有任何CloudFlare绕过机制,所以如果它从wget工作,那么它不应该从Python请求也工作吗?当然,对于wget,我仍然需要给cookie值,否则wget也会击中CloudFlare。使用wget(成功结果):

wget "https://1stkissmanga.io/" -U "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0" --header="Cookie: __cf_bm=<some long string with dots and other special characters>"

与python:

headers = {"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0",} cookies = {"__cf_bm": "<some long string with dots and other special characters>",}

url = "https://1stkissmanga.io/" res = requests.get(url, headers=headers, cookies=cookies)

我也试过把cookie放到header中,比如

headers = {"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0", "cookie": "__cf_bm=<some long string with dots and other special characters>",}

和执行res = requests.get(url, headers=headers),但结果是相同的。无论我做什么,请求始终停止CloudFlare保护。

不知道下一步该怎么做,CloudFlare代理现在没有问题。

你应该在Cookie"Key,不是dict。应该是这样的{"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0", "Cookie": "cf_clearance=<some hash here>; cf_chl_2=<some hash here>; cf_chl_prog=x11; XSRF-TOKEN=<some hash here>; laravel_session=<some hash here>; __cf_bm=<some hash here>;"}

完整的代码看起来像这样,但请记住,检查工作10-15分钟,之后您将需要从浏览器中获取新的cookie。

import requests
h = {
"user-agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:97.0) Gecko/20100101 Firefox/97.0", 
"Cookie": "cf_clearance=<some hash here>; cf_chl_2=<some hash here>; cf_chl_prog=x11; XSRF-TOKEN=<some hash here>; laravel_session=<some hash here>; __cf_bm=<some hash here>;"
}
requests.get(url, headers=h)

最新更新