提取文本文件包含类似下面的HTML代码(词“登记”和“飞”是固定在下面的段落):的Python + BeautifulSoup - 通过搜索标准
<TR>
<TD class=CAT2 width="10%">Registration</TD>
<TD class=CAT1 width="20%">02 Mar 2006</TD></TR>
<TR>
<TD class=CAT2 width="10%">Flying</TD>
<TD class=CAT1 width="20%">24 Jun 2005</TD></TR>
我想提取它们,把为:
月24日注册2006年03月02日
飞行2005
我正在使用BeautifulSoup find_next_sibling,但它不返回任何内容。出了什么问题?
from bs4 import BeautifulSoup
url = r"C:\example.html"
page = open(url)
soup = BeautifulSoup(page.read())
aa = soup.find_next_sibling(text='Registration')
print aa
,如果你改变'将工作 “登记:”''以 “注册”' –
感谢洛基和巴拉克马诺斯。 –