我试图解析一个网站来提取人名和国家。如何获得以下兄弟::文本()和以下兄弟:: b?
页面有时看起来像:
<th>Inventors:</th>
<td align="left" width="90%">
<b>Harvey; John Christopher</b> (New York, NY)<b>, Cuddihy; James William</b> (New York, NY)
</td>
我能得到使用国家
//th[contains(text(), "Inventors:")]/following-sibling::td/b[contains(text(),";")]/following-sibling::text()
[(New York, NY), (New York, NY)]
有时页面看起来像(添加围绕国名):
<th>Inventors:</th>
<td align="left" width="90%">
<b>Harvey; John Christopher</b> (New York, <b>NY</b>)<b>, Cuddihy; James William</b> (New York, <b>NY</b>)
</td>
我可以得到国家:
//th[contains(text(), "Inventors:")]/following-sibling::td/b[contains(text(),";")]/following-sibling::b
[NY, NY]
现在,我希望能够在两种情况下获得国家。
我试着用:
//th[contains(text(), "Inventors:")]/following-sibling::td/b[contains(text(),";")]/following-sibling::*[self::text() or self::b]
但当时我只得到 “B” S ...
我也试过:
//.../following-sibling::text() | //.../following-sibling::b
但我也只得到“b”...
任何想法为什么这不按预期方式工作?任何解决方案来获得这两个条目