Formatting Grabbed Data From Dropdwon Boxes And Adding Data Into The Result In Python Beautifulsoup
I have the following code that partially runs but with a very messy result display. I need help on how to get the additional data as well formatting of the output. from urllib.requ
Solution 1:
import requests
from bs4 import BeautifulSoup
from pprint import pp
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0'
}
adds = [
'0x639AD7c49EC616a64e074c21a58608C0d843A8a3'
]
def main(url):
with requests.Session() as req:
req.headers.update(headers)
for add in adds:
r = req.get(url.format(add))
soup = BeautifulSoup(r.text, 'lxml')
goal = soup.select('div.card-body')
data = {
'ContractCreator': goal[1].select_one('a.hash-tag').text,
'Txn': goal[1].select('a.hash-tag')[1].text,
'Token Name': goal[1].select('a')[3].text,
'Trans Count': soup.select_one('p.mr-2 a').text,
'Balance': goal[0].select_one('.col-md-8').get_text(strip=True),
'Tokens ValCount': " / ".join(list(goal[0].select_one('.position-relative').stripped_strings)[:2]),
'Token List': [x.get_text(strip=True) for x in soup.select('.list.list-unstyled strong, .list-name')]
}
pp(data)
main('https://bscscan.com/address/{}')
Output:
{'ContractCreator': '0x7ab96edb99e1faa06238609947792038520f1a3c',
'Txn': '0x51a8db6ac707dcd9644b5400b533c9bbe95243054c9c67e8a8aeeab38c7f7e79',
'Token Name': 'TripCandy (CANDY)',
'Trans Count': '2,880',
'Balance': '0.498586644749540253 BNB',
'Tokens ValCount': '$727.19 / 3',
'Token List': ['BEP-20 Tokens',
'Minereum BSC (MNEB)',
'Neftipedia (NFT)',
'TripCandy (CANDY)']}
Post a Comment for "Formatting Grabbed Data From Dropdwon Boxes And Adding Data Into The Result In Python Beautifulsoup"