Skip to main content
 首页 » 编程设计

python之关于数据类型的 BeautifulSoup 代码问题

2025年05月04日20Leo_wl

我不明白为什么它不起作用。

现在我在财务表上工作:

https://finance.yahoo.com/quote/ATVI/financials?p=ATVI

我没有得到的是 find_all 方法的结果。 当我在上面放更多点符号时,比如 find_all('td').children 它抛出一个错误。 也许我的错误是因为 find_all 的返回值是一个对象,而不是一个列表,对吗?

我不知道为什么下面的代码不起作用。

span_tag1=soup.find_all('td') 
for i in span_tag1.children: 
    print(i.get_text) 

请您参考如下方法:

由于您正在查找 all td 元素(这会创建一个列表),因此您需要遍历每个元素,然后找到每个 的子元素td 元素:

for td in soup.find_all('td'): 
    for child in td.children: 
        print(child.get_text())