The snippet below works fine not until the other day. Is there any way to extract all the data inside this div class=”row mb-4″ easily. What I am thinking is that if additional changes will be made to the page, still the script will not be affected.
JavaScript
x
34
34
1
import requests
2
from bs4 import BeautifulSoup
3
4
header = {
5
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0'
6
}
7
8
url = "https://bscscan.com/token/"
9
token = "0x4ce1a5cb12151423ea479cfd0c52ec5021d108d8"
10
tokenurl = str(url)+str(token)
11
12
contractpage = requests.get(tokenurl,header)
13
ca = BeautifulSoup(contractpage.content, 'html.parser')
14
tokenholders = ca.find(id='ContentPlaceHolder1_tr_tokenHolders').get_text()
15
tokenholdersa = (((tokenholders.strip().strip("Holders:")).strip()).strip(" a ")).strip()
16
tholders = ((((tokenholders.strip()).strip("Holders:")).strip()).strip(" a ")).strip()
17
tokenaname = ca.find('span', class_='text-secondary small').get_text().strip()
18
19
def get_transfer_count(str:token)->str:
20
with requests.Session() as s:
21
s.headers = {'User-Agent':'Mozilla/5.0'}
22
r = s.get(f'https://bscscan.com/token/{token}')
23
try:
24
sid = re.search(r"var sid = '(.*?)'", r.text).group(1)
25
r = s.get(f'https://bscscan.com/token/generic-tokentxns2?m=normal&contractAddress={token}&a=&sid={sid}&p=1')
26
return re.search(r"var totaltxns = '(.*?)'", r.text).group(1)
27
except:
28
pass
29
transcount = get_transfer_count(token)
30
31
print ("Token: ", tokenaname)
32
print ("Holders: ", tholders)
33
print ("Transfers: ", transcount)
34
Previous Output:
JavaScript
1
4
1
Token: Binemon
2
Holders: 27,099
3
Transfers: 439,636
4
Wanted Improved Output:
JavaScript
1
17
17
1
Token: Binemon
2
PRICE: $0.01 @ 0.000037 BNB (-22.41%)
3
Fully Diluted Market Cap: $14,011,783.50
4
5
Total Supply: 975,000,000 BIN
6
Holders: 27,099 addresses
7
Transfers: 439,636
8
Contract: 0xe56842ed550ff2794f010738554db45e60730371
9
Decimals: 18
10
Official Site: https://binemon.io/
11
Social Profiles:
12
Tweets by BinemonNft
13
https://t.me/binemonchat
14
https://docs.binemon.io/
15
https://coinmarketcap.com/currencies/binemon/
16
https://www.coingecko.com/en/coins/binemon/
17
Advertisement
Answer
Try:
JavaScript
1
31
31
1
import requests
2
from bs4 import BeautifulSoup
3
4
header = {
5
"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0",
6
}
7
tokenurl = (
8
"https://bscscan.com/token/0x7083609fce4d1d8dc0c979aab8c869ea2c873402"
9
)
10
11
contractpage = requests.get(tokenurl, headers=header)
12
ca = BeautifulSoup(contractpage.content, "html.parser")
13
14
name = ca.h1.span.get_text(strip=True)
15
price = ca.select_one(".card-body .d-block").get_text(strip=True)
16
cap = ca.select_one("#pricebutton").get_text(strip=True)
17
18
print("Token:", name)
19
print("PRICE:", price)
20
print("Fully Diluted Market Cap:", cap)
21
print()
22
23
for c in ca.select(".row .col-md-8"):
24
pt = c.find_previous(class_="col-md-4").get_text(strip=True)
25
t = c.get_text(strip=True, separator=" ").split("(")[0]
26
if pt == "Social Profiles:":
27
links = [a["href"].strip() for a in c.select("a")]
28
print(pt, *links, sep="nt")
29
else:
30
print(pt, t)
31
Prints:
JavaScript
1
19
19
1
Token: Binance-Peg Polkadot Token
2
PRICE: $30.35@ 0.079643 BNB(-10.39%)
3
Fully Diluted Market Cap: $485,657,455.49
4
5
Total Supply: 15,999,999.991309 DOT
6
Holders: 80,065 addresses
7
Transfers: -
8
Contract: 0x7083609fce4d1d8dc0c979aab8c869ea2c873402
9
Decimals: 18
10
Official Site: https://polkadot.network/
11
Social Profiles:
12
https://polkadot.network/blog
13
https://reddit.com/r/dot
14
Tweets by polkadotnetwork
15
https://github.com/w3f
16
https://polkadot.network/PolkaDotPaper.pdf
17
https://coinmarketcap.com/currencies/polkadot-new/
18
https://www.coingecko.com/en/coins/polkadot/
19