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

标签 python web-scraping beautifulsoup

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

现在我在财务表上工作:

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

关于python - 关于数据类型的 BeautifulSoup 代码问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55509920/

相关文章:

python - 使用 pdb 调试到子进程?

python - 1 行(所有数据)到 10 行将数据从 pandas 库拆分到数据帧

python - BeautifulSoup 连续 block

python - 抓取嵌套标签

python - 表单操作根本不触发

python - 默认解释器总是重置

python - 如何将 unicode 文本转换为 python 可以读取的文本,以便我可以在网络抓取结果中找到该特定单词?

rvest:给定多个列表,返回空节点的 NA

python - 如何在使用 pandas 和 matplotlib 时更改我的 x 轴?

r - 如何在 R 中自动下载多个链接断开的图像?