【发布时间】:2015-05-08 05:01:53
【问题描述】:
如果您能给我一些指导,告诉我如何在使用 beautifulsoup 时获取下面的出生日期“1723 年 6 月 16 日”,我将不胜感激。现在使用我的代码,我设法获取了您在下面的结果中看到的值,但是我只需要获取 1723 年 6 月 16 日的值。有什么建议吗?
我的代码:
birth = soup.find("table",{"class":"infobox"})
test = birth.find(text='Born')
next_cell = test.find_parent('th').find_next_sibling('td').get_text()
print next_cell
结果:
16 June 1723 NS (5 June 1723 OS)Kirkcaldy, Scotland,Great Britain
【问题讨论】:
-
您的数据可能更容易从
td标记中的子标记中提取。是否可以显示该表格的 HTML? -
出生 -
出生 1723 年 6 月 16 日 NS
标签: python html beautifulsoup html-parsing