【问题标题】:BeautifulSoup, 'ResultSet' object has no attribute 'find_all'BeautifulSoup,“ResultSet”对象没有属性“find_all”
【发布时间】:2013-03-30 14:02:23
【问题描述】:

我阅读了与我的问题相关的其他线程,但它并没有解决问题。

<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 循环对其进行迭代,所以不确定为什么会导致错误。请给点意见?

【问题讨论】:

  • 如果这个问题得到解决,那么要关闭问题,您应该将您的解决方案作为答案发布,并接受它...
  • 唯一的障碍是我认为这个问题可能必须有 48 小时的历史......

标签: python-2.7 beautifulsoup findall


【解决方案1】:

好的,代码少了一行:

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

cards_table 是一个列表,因此我们必须在对表使用find_all 方法之前对其进行迭代。

【讨论】:

    猜你喜欢
    • 2016-12-19
    • 1970-01-01
    • 2018-08-06
    • 1970-01-01
    • 2017-04-25
    • 2016-08-16
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    相关资源
    最近更新 更多