小编Mat*_*ira的帖子

如何使用 BeautifulSoup 查找元素的父标签?

我想知道我是否可以使用漂亮的汤,将 html 行排成几行:

<tr id="12590559" class="">
<td>
<span class="he16-1 tip-top" title="Cracker"></span>
</td>
<td>
cracker.crc
</td>
Run Code Online (Sandbox Code Playgroud)

在那个例子中,我想提取 id 但使用标题信息:

soup = BeautifulSoup(lista.content, "lxml")
id = soup.find(attrs={"title": "Cracker"})
Run Code Online (Sandbox Code Playgroud)

我可以得到

soup = BeautifulSoup(lista.content, "lxml")
id = soup.find(attrs={"title": "Cracker"})
Run Code Online (Sandbox Code Playgroud)

但我也想得到id. 我可以用BeautifulSoup来排列几条线吗?

python beautifulsoup python-3.x

5
推荐指数
1
解决办法
5544
查看次数

标签 统计

beautifulsoup ×1

python ×1

python-3.x ×1