小编al *_*vic的帖子

如何从beautifulSoup中提取多个html标签?

我正在尝试使用beautifulSoup从html页面中提取几个标签。该页面包含1-100的排名列表,因此我想提取每个项目的所有和标签。

我尝试使用以下代码:

info = soup.find_all('tbody')

for item in info.find_all('tr'):
    for cells in item.find_all('td'):
        print (cells)
Run Code Online (Sandbox Code Playgroud)

但保持相同的AttributeError:ResultSet对象没有属性'find_all'。您可能正在将项目列表像单个项目一样对待。当您打算调用find()时,是否调用过find_all()?

info = soup.find_all('tbody')
Run Code Online (Sandbox Code Playgroud)

输出:tbody

<tr

<td class="field-index ">1/td

<td class="field-release "><a class="link-release" href="/release/712">The Beatles [White Album]</a>/td

<td class="field-performer "><a class="link-performer" href="/artist/41">The Beatles</a></td

<td class="field-covers text-right">1633/td

</tr
Run Code Online (Sandbox Code Playgroud)

对于<tr>此页面的每个标签,我想将每个<td>标签拉入其中。因此,我首先需要返回:

1
The Beatles [White Album]
The Beatles
1633
Run Code Online (Sandbox Code Playgroud)

请让我知道如何解决此问题。

python beautifulsoup web-scraping

2
推荐指数
1
解决办法
45
查看次数

标签 统计

beautifulsoup ×1

python ×1

web-scraping ×1