Grabbing top table data returns a blank display

Viewed 56

I am really wondering and in panic mode as quite a few snippet I have been using is problematic. This one used to produced desired output but all of a sudden, a blank output is displayed.

import requests, random, re
from bs4 import BeautifulSoup

headers = {
    "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0",
}

url = "https://bscscan.com/token/generic-tokenholders2?m=normal&a="
token = "0xe56842ed550ff2794f010738554db45e60730371"

holdersurl = str(url) + str(token)
s = requests.Session()
r = requests.get(holdersurl, headers=headers)
soupblockdetails = BeautifulSoup(r.content, 'html.parser')
rowsblockdetails = soupblockdetails.findAll('table')[0].findAll('tr', limit=6)

for row in rowsblockdetails[1:]:
    rank = row.find_all('td')[0].text[0:].strip()
    address = row.find_all('td')[1].text[0:].strip()
    amount = row.find_all('td')[2].text[0:].strip()
    percentage = row.find_all('td')[3].text[0:]
    value = row.find_all('td')[4].text[0:]
         
    try:
        calock=row.select_one("i.far.fa-file-alt.text-secondary")['title']
        calock = "Contract"
    except:
        calock = "Unlocked"

    print ("{}  {}-%  {:>8}  {:>23} {} {} ".format(rank, address, amount, percentage, value, calock))

Previous Output: #-- Working output previously

1   0xbbda05ea467ad348212dade5c38c11910c14e83e  202,543,296.764175197290329227  20.77%     $3,054,207.08    Unlocked    
2   UniCrypt: Token Vesting                     150,000,000                     15.38%     $2,261,892.00    Contract    
3   PancakeSwap V2: BIN 17                      99,217,566.546415684406759104   10.17%     $1,496,129.47    Contract
4   Binemon: BIN Token                          27,010,296.006072937294814033    2.77%       $407,295.82    Contract
5   0x81da471feb4a45438053dc05e709be056ec26c39  14,865,062                       1.52%       $224,154.43    Unlocked
1 Answers

Now try these code you run these code multiple time the website will block you Now we add `cookies' it will run perfectly

import requests, random, re
    from bs4 import BeautifulSoup
    
    headers = {
        "User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:92.0) Gecko/20100101 Firefox/92.0",
    }
    cookies= {'session': '17ab96bd8ffbe8ca58a78657a918558'}
    headers=headers
    cookies=cookies
    url = "https://bscscan.com/token/generic-tokenholders2?m=normal&a="
    token = "0xe56842ed550ff2794f010738554db45e60730371"
    
    holdersurl = str(url) + str(token)
    s = requests.Session()
    r = requests.get(holdersurl, headers=headers)
    soupblockdetails = BeautifulSoup(r.content, 'html.parser')
    rowsblockdetails = soupblockdetails.findAll('table')[0].findAll('tr', limit=6)
    
    for row in rowsblockdetails[1:]:
        rank = row.find_all('td')[0].text[0:].strip()
        address = row.find_all('td')[1].text[0:].strip()
        amount = row.find_all('td')[2].text[0:].strip()
        percentage = row.find_all('td')[3].text[0:]
        value = row.find_all('td')[4].text[0:]
             
        try:
            calock=row.select_one("i.far.fa-file-alt.text-secondary")['title']
            calock = "Contract"
        except:
            calock = "Unlocked"
    
        print ("{}  {}-%  {:>8}  {:>23} {} {} ".format(rank, address, amount, percentage, value, calock))
Related