【发布时间】:2016-05-29 15:08:52
【问题描述】:
对于这部分html代码:
html3= """<a name="definition"> </a>
<h2><span class="sectioncount">3.342.2323</span> Content Logical Definition <a title="link to here" class="self-link" href="valueset-investigation"><img src="ta.png"/></a></h2>
<hr/>
<div><p from the following </p><ul><li>Include these codes as defined in http://snomed.info/sct<table><tr><td><b>Code</b></td><td><b>Display</b></td></tr><tr><td>34353553</td><td>Examination / signs</td><td/></tr><tr><td>35453453453</td><td>History/symptoms</td><td/></tr></table></li></ul></div>
<p> </p>"""
我将使用 beautifulsoup 来查找其文本等于“内容逻辑定义”的 h2 和下一个兄弟。但是beautifulsoup 找不到h2。以下是我的代码:
soup = BeautifulSoup(html3, "lxml")
f= soup.find("h2", text = "Content Logical Definition").nextsibilings
这是一个错误:
AttributeError: 'NoneType' object has no attribute 'nextsibilings'
文本中有几个“h2”,但唯一使这个 h2 独一无二的字符是“内容逻辑定义”。找到这个h2之后,我要从表中提取数据并在它下面列出。
【问题讨论】:
-
试试
nextsiblings???
标签: python html beautifulsoup html-parsing bs4