如何使用Python从铸造站点获取Candy Machine V2 ID
我正在尝试从任何网站(或至少大多数网站)获取糖果机。我从网站上获取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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.