如何使用Python从铸造站点获取Candy Machine V2 ID

发布于 2025-01-30 18:15:02 字数 1132 浏览 4 评论 0原文

我正在尝试从任何网站(或至少大多数网站)获取糖果机。我从网站上获取DOM并获得脚本(我发现它的“ react_app_candy_machine_id”是值是CMID)。但是我不知道该如何从Python读取它,我将脚本代码从网站上获取为字符串,soup 。我一直在仔细阅读脚本,并以某种方式获得可变值,但我认为不应该这样做。

import requests
from bs4 import BeautifulSoup as bs
from urllib.parse import urljoin

session = requests.Session()
session.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"

# the first link I saw with CMv2
url = 'https://lazy-alpha.vercel.app/'

html = session.get(url).content
soup = bs(html, "html.parser")
script_files = []

for script in soup.find_all("script"):
    if script.attrs.get("src"):
        script_url = urljoin(url, script.attrs.get("src"))
        script_files.append(script_url)
    
with open("javascript_files.txt", "w") as f:
    rsp = requests.get(script_files[0]).text
    #just checking if I'm going crazy or not yet
    if 'REACT_APP_CANDY_MACHINE_ID' in rsp:
        print('Exists')

我已经尝试了一段时间了,以防万一,代码上有一些奇怪的事情,只是为了使您更加清楚。提前致谢 :)

I'm trying to get the candy machine from any website (or at least most of them). I get the DOM from the website and got the script (where I've discovered there's 'REACT_APP_CANDY_MACHINE_ID' that it's value is the cmid). But I don't know how to read it from Python, I got the script code as string with a GET from the site and soup. I've been looking to iterate through the script and somehow get the variable value but I think it shouldn't be done like this.

import requests
from bs4 import BeautifulSoup as bs
from urllib.parse import urljoin

session = requests.Session()
session.headers["User-Agent"] = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"

# the first link I saw with CMv2
url = 'https://lazy-alpha.vercel.app/'

html = session.get(url).content
soup = bs(html, "html.parser")
script_files = []

for script in soup.find_all("script"):
    if script.attrs.get("src"):
        script_url = urljoin(url, script.attrs.get("src"))
        script_files.append(script_url)
    
with open("javascript_files.txt", "w") as f:
    rsp = requests.get(script_files[0]).text
    #just checking if I'm going crazy or not yet
    if 'REACT_APP_CANDY_MACHINE_ID' in rsp:
        print('Exists')

I've been trying for a while, just in case there's something weird on the code, it's just to make things a little more clear for you. Thanks in advance :)

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

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

发布评论

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

评论(1

对风讲故事 2025-02-06 18:15:02

react_app_candy_machine_id通常来自env文件,因此我认为您无法获得此功能,但是如果您可以以某种方式获得网站发送的RPC请求,该请求是为了获取CM数据,那么您可以执行相同的操作并获取CM数据。

REACT_APP_CANDY_MACHINE_ID usually comes from the ENV file So i don't think you would be able to get that but if you can somehow get the RPC requests that the Website is sending for fetching CM Data then you can do the same and get the CM data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文