一个工作片段不能再抓取它以前的数据
A working snippet can no longer grab the data it used to
我想弄清楚为什么片段 get_transfer_count 的部分不起作用。我以前用过这个代码,直到最近都很好。
import requests
from bs4 import BeautifulSoup
header = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0",
}
tokenurl = (
"https://bscscan.com/token/0xe56842ed550ff2794f010738554db45e60730371"
)
token = "0xe56842ed550ff2794f010738554db45e60730371"
contractpage = requests.get(tokenurl, headers=header)
ca = BeautifulSoup(contractpage.content, "html.parser")
name = ca.h1.span.get_text(strip=True)
price = ca.select_one(".card-body .d-block").get_text(strip=True)
cap = ca.select_one("#pricebutton").get_text(strip=True)
def get_transfer_count(str:token)->str:
with requests.Session() as s:
s.headers = {'User-Agent':'Mozilla/5.0'}
r = s.get(f'https://bscscan.com/token/{token}')
try:
sid = re.search(r"var sid = '(.*?)'", r.text).group(1)
r = s.get(f'https://bscscan.com/token/generic-tokentxns2?m=normal&contractAddress={token}&a=&sid={sid}&p=1')
return re.search(r"var totaltxns = '(.*?)'", r.text).group(1)
except:
pass
transcount = get_transfer_count(token)
print("Token:", name)
print("PRICE:", price)
print("Fully Diluted Market Cap:", cap)
print ("Transfer: ", transcount)
print()
之前的输出:
Token: Binemon
PRICE: [=11=].02@ 0.000040 BNB(-17.38%)
Fully Diluted Market Cap: ,003,573.00
Transfer: 440,283
预期输出:
Token: Binemon
PRICE: [=12=].02@ 0.000040 BNB(-17.38%)
Fully Diluted Market Cap: ,003,573.00
Transfer: 440,283 #-- this part no longer works
您缺少导入:
import re
你没有得到异常,因为你使用的是一个简单的 except:
except:
pass
不推荐这样做,因为它会导致这样的错误。
我想弄清楚为什么片段 get_transfer_count 的部分不起作用。我以前用过这个代码,直到最近都很好。
import requests
from bs4 import BeautifulSoup
header = {
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0",
}
tokenurl = (
"https://bscscan.com/token/0xe56842ed550ff2794f010738554db45e60730371"
)
token = "0xe56842ed550ff2794f010738554db45e60730371"
contractpage = requests.get(tokenurl, headers=header)
ca = BeautifulSoup(contractpage.content, "html.parser")
name = ca.h1.span.get_text(strip=True)
price = ca.select_one(".card-body .d-block").get_text(strip=True)
cap = ca.select_one("#pricebutton").get_text(strip=True)
def get_transfer_count(str:token)->str:
with requests.Session() as s:
s.headers = {'User-Agent':'Mozilla/5.0'}
r = s.get(f'https://bscscan.com/token/{token}')
try:
sid = re.search(r"var sid = '(.*?)'", r.text).group(1)
r = s.get(f'https://bscscan.com/token/generic-tokentxns2?m=normal&contractAddress={token}&a=&sid={sid}&p=1')
return re.search(r"var totaltxns = '(.*?)'", r.text).group(1)
except:
pass
transcount = get_transfer_count(token)
print("Token:", name)
print("PRICE:", price)
print("Fully Diluted Market Cap:", cap)
print ("Transfer: ", transcount)
print()
之前的输出:
Token: Binemon
PRICE: [=11=].02@ 0.000040 BNB(-17.38%)
Fully Diluted Market Cap: ,003,573.00
Transfer: 440,283
预期输出:
Token: Binemon
PRICE: [=12=].02@ 0.000040 BNB(-17.38%)
Fully Diluted Market Cap: ,003,573.00
Transfer: 440,283 #-- this part no longer works
您缺少导入:
import re
你没有得到异常,因为你使用的是一个简单的 except:
except:
pass
不推荐这样做,因为它会导致这样的错误。