【问题标题】:Grabbing top table data returns a blank display抓取顶部表格数据返回空白显示
【发布时间】:2021-09-20 12:20:09
【问题描述】:

我真的很想知道并且处于恐慌模式,因为我一直在使用的很多 sn-p 是有问题的。这一个用于产生所需的输出,但突然间,显示一个空白输出。

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: #-- 之前的工作输出

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

【问题讨论】:

    标签: python python-3.x beautifulsoup


    【解决方案1】:

    现在试试这些代码你多次运行这些代码网站会阻止你现在我们添加“cookies”它会完美运行

    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))
    

    【讨论】:

    • 信息量很大。这可能是我拥有的脚本的问题。问题,您是如何生成值 17ab96bd8ffbe8ca58a78657a918558
    • 去网站的website再去网站的xhr会提到网站的cookies
    • 你的cookies和我的不一样?我必须检查什么标签。我正在使用 Mozilla。
    猜你喜欢
    • 1970-01-01
    • 2019-02-13
    • 2019-08-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多