小编Tom*_*ain的帖子

如何在 BeautifulSoup 中获取下一个 td 值

Python 新手,我尝试使用 BeautifulSoup 使用以下代码从 etherscan.com 网页中提取“ETH 余额”:

import bs4, requests

res = requests.get('https://etherscan.io/address/0x93673eeed88fda9423b8037374164383df54aec1')
res.raise_for_status()

soup = bs4.BeautifulSoup(res.text, 'html.parser')
ethBal = soup.find("td", text="ETH Balance").find_next("td").text

print('The ETH blance is '+ ethBal)
Run Code Online (Sandbox Code Playgroud)

但是我不断收到错误消息:

Traceback (most recent call last):
  File "/Users/tfountain/Desktop/python_work/c2.py", line 7, in <module>
    ethBal = soup.find("td", text="ETH Balance").find_next("td").text
AttributeError: 'NoneType' object has no attribute 'find_next'
Run Code Online (Sandbox Code Playgroud)

我哪里出错了,获得 ETH 余额的最佳方式是什么?

python beautifulsoup

-1
推荐指数
1
解决办法
4792
查看次数

标签 统计

beautifulsoup ×1

python ×1