Python 如何使用BeautifulSoup4从HTML表中提取所有项?

Python 如何使用BeautifulSoup4从HTML表中提取所有项?,python,python-3.x,parsing,beautifulsoup,html-parsing,Python,Python 3.x,Parsing,Beautifulsoup,Html Parsing,下面是HTML,它是我正在抓取的一个更大网站的一部分: 基本上,我希望我的输出是: Breed: Shih Tzu Price: $850 Gender: Male Nickname: Wade Age: 16 Weeks Old Color/Markings: red and white Size at Maturity: Small 等等,等等。我试着找到所有的tr标签,所有的td标签,和所有的b标签,但没有一个给出我要寻找的输出或给出一个错误 提前感谢您的回复 您可以使用嵌套列表: fr

下面是HTML,它是我正在抓取的一个更大网站的一部分:

基本上,我希望我的输出是:

Breed: Shih Tzu
Price: $850
Gender: Male
Nickname: Wade
Age: 16 Weeks Old
Color/Markings: red and white
Size at Maturity: Small
等等,等等。我试着找到所有的tr标签,所有的td标签,和所有的b标签,但没有一个给出我要寻找的输出或给出一个错误


提前感谢您的回复

您可以使用嵌套列表:

from bs4 import BeautifulSoup as soup
d = soup(content, 'html.parser')
new_results = [[c.text.replace('\n', '') for c in i.find_all('td')] for i in d.find_all('tr')]
for i in new_results:
  print(' '.join(i))
输出:

Breed: Shih Tzu
Price: $850
Gender: Male Male
Nickname: Wade
Age: 16 Weeks Old
Color/Markings: red and white
Size at Maturity: Small
Availability Date: 08/01/2018
Shipping Area: Pick Up Only
Payment Method: Credit Cards, Cash

谢谢,这是可行的,但它来自其他表,我不希望完整的html包含这些表。有没有办法只从某个类中的表中提取?我想要的表格包含在`class=“properties”>中,甚至更简单,只需提取具有特定标题的行,比如说如果我只想要品种、价格和年龄?非常感谢。