Search code examples
web-scrapingbinancepython-requests-htmlbscscan

Scrape BSCScan Token Holdings Page


I'm trying to get data from this page

https://bscscan.com/tokenholdings?a=0xFAe2dac0686f0e543704345aEBBe0AEcab4EDA3d

But the Website owner doesn't provide endpoints APIs for this purpose. So I tried to achieve it in different ways:

-USING DRYSCRAPE but the library seems to be abandoned;

-USING REQUESTS but the data are provided dinamically by javascript;

-USING REQUESTS HTML but even in this case the data doesn't seems to be loaded.

I would like to ignore selenium cause it's slow but I don't know how to solve this issue. Anyone has a solution that could work? The data I need is the table containing the tokens of the wallet. Thank U in advice and hv a nice day.


Solution

  • You can do it with requests-html, for example let's grab the symbol of the first row:

    from requests_html import HTMLSession
    
    session = HTMLSession()
    
    url='https://bscscan.com/tokenholdings'
    token={'a': '0xFAe2dac0686f0e543704345aEBBe0AEcab4EDA3d'}
    
    r = session.get(url, params=token)
    r.html.render(sleep=2)
    
    binance_row = r.html.find('tbody tr', first=True)
    symbol = binance_row.find('td')[2].text
    
    print(symbol)
    

    Output:

    BNB