【发布时间】:2021-08-20 02:06:53
【问题描述】:
我有这个 html 示例
<html>
<body>
....
<p id="book-1" class="abc">
<b>
<a href="xxx.html">book-1</a>
<a href="xxx.html">section</a>
</b>
"I have a lot of "
<i>different</i>
"text, and I want "
<i>all</i>
" text and we may or may not have italic surrounded text."
</p>
....
我目前拥有的 xpath 是这样的:
@"/html[1]/body[1]/p[1]/text()"
这给出了这个结果:
我有很多
但我想要这个结果:
I have a lot of different text, and I want all text and we may or may not have italic surrounded text.
感谢您的帮助。
【问题讨论】:
-
我认为你不能单独使用 xpath 来做到这一点,since you can't select a node without its children。要做你想做的事,你必须使用宿主语言。比如python中的BeautifulSoup。
-
如果我真的找不到方法,那么我将不得不从 p 中提取,然后使用我的过程来做一些正则表达式。谢谢。
标签: xpath