如何在 GET 请求上使用 Python 绕过 Cloudflare?

发布于 2025-01-19 10:03:00 字数 680 浏览 2 评论 0原文

我想在 GET 请求上绕过 Cloudflare 我尝试过使用 Cloudscraper,它过去对我有用,但现在似乎已经过时了。

我尝试过:

import cloudscraper
import requests
ses = requests.Session()
ses.headers = {
    'referer': 'https://magiceden.io/',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36',
    'accept': 'application/json'
}
scraper = cloudscraper.create_scraper(sess=ses)
hookLink = f"https://magiceden.io/launchpad/planetarians"
meG = scraper.get("https://api-mainnet.magiceden.io/launchpads/planetarians")
print(meG.status_code)
print(meG.text)

问题似乎是我收到了请求的验证码

I want to bypass Cloudflare on a GET request I have tried using Cloudscraper which worked for me in the past but now seems decreped.

I tried:

import cloudscraper
import requests
ses = requests.Session()
ses.headers = {
    'referer': 'https://magiceden.io/',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36',
    'accept': 'application/json'
}
scraper = cloudscraper.create_scraper(sess=ses)
hookLink = f"https://magiceden.io/launchpad/planetarians"
meG = scraper.get("https://api-mainnet.magiceden.io/launchpads/planetarians")
print(meG.status_code)
print(meG.text)

The issue seems to be that I'm getting a captcha on the request

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

木槿暧夏七纪年 2025-01-26 10:03:02

Python库运行良好(我从来不知道),问题是您的用户代理。 CloudFlare使用某种额外的检查来确定您是否伪造它。

对我来说,以下任何工作:

ses.headers = {
    'referer': 'https://magiceden.io/',
    'accept': 'application/json'
}

ses.headers = {
    'accept': 'application/json'
}

也只是:

scraper = cloudscraper.create_scraper()
meG = scraper.get("https://api-mainnet.magiceden.io/launchpads/planetarians")

编辑:

您可以使用此dict语法代替伪造用户代理(根据手册)

scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'chrome',
        'platform': 'windows',
        'desktop': True
    }
)

The python library works well (I never knew about it), the issue is your user agent. Cloudflare uses some sort of extra checks to determine whether you're faking it.

For me, any of the following works:

ses.headers = {
    'referer': 'https://magiceden.io/',
    'accept': 'application/json'
}

ses.headers = {
    'accept': 'application/json'
}

And also just:

scraper = cloudscraper.create_scraper()
meG = scraper.get("https://api-mainnet.magiceden.io/launchpads/planetarians")

EDIT:

You can use this dict syntax instead to fake the user agent (as per the manual)

scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'chrome',
        'platform': 'windows',
        'desktop': True
    }
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文