python-2.7 - BeautifulSoup, 'ResultSet' 对象没有属性 'find_all'

标签 python-2.7 beautifulsoup findall

我阅读了与我的问题相关的其他主题,但没有解决问题。

<h2 class="tabellen_ueberschrift al">Cards</h2>
<div class="fl" style="width:49%;">     
<table class="tabelle_grafik lh" cellpadding="2" cellspacing="1">
        <tr>
            <th class="al" colspan="3">CA Osasuna</th>              
        </tr>

            <td class="s10 al">
                <a href="/en/sisi/profil/spieler_51713.html" class="fb s10" title="Sisi">Sisi</a>
                <br />
                26.  min. 2. yellow card, Time wasting              </td>
        </tr>

我想获取表格中所有的 a 标签(会有几个),所以我的代码是这样的:

header = soup.find('h2', text="Cards")
cards_table = header.find_next_siblings(limit=2)
for row in cards_table.find_all('a'):
    print row

这让我振作起来

AttributeError: 'ResultSet' object has no attribute 'find_all'

cards_table 是一个表,我用 for 循环对其进行迭代,所以不确定为什么会导致错误。有想法吗?

最佳答案

好的,代码少了一行:

for line in cards_table:
    for row in line.find_all('a'):
        print row

cards_table 是一个列表,所以我们必须先遍历它,然后才能对表使用 find_all 方法。

关于python-2.7 - BeautifulSoup, 'ResultSet' 对象没有属性 'find_all',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15879948/

相关文章:

python - 将 lxml.etree 导入 python 时出现错误

arrays - Groovy 过滤器二维数组

c# - 将 List.FindAll() 与 lambda 一起使用的 VB.NET 语法是什么?

python - 如何指定变量作为 re.sub 中的第一个参数

python - 从 3 个 View 中创建 3D 对象

python - pip 和 easy_install 安装 python 包的麻烦

python - 初学者学习 Python 屏幕抓取的最佳方式

Python3 beautifulsoup模块 'NoneType'错误

python - BeautifulSoup 中不满足条件的标签可以返回吗?

python - 为什么 findall 返回空字符串?