美丽的汤和提取的价值
Beautiful soup and extracting values
如果您能指导我如何在使用 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
添加这个
而不是最后一个打印语句
print ' '.join(str(next_cell).split()[:3])
如果您能指导我如何在使用 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
添加这个
而不是最后一个打印语句print ' '.join(str(next_cell).split()[:3])