我很难获得位于两个标签之间的特定文本。
我的意思是,想要获得Text after em tag. I want to get this.
和text after this p tag. I also want to get this.
。
有没有办法做到这一点?
提前谢谢。
<article>
<h1 id='h1'>Heading 1</h1>
<img src='mypath/pictures/pic.jpg'></img>
<p></p>
<div id='div1'>
<time datetime='2016'>2016</time>
</div>
<br></br>
<em>my location, TN, United States</em>
Text after em tag. I want to get this.
<p></p>
text after this p tag. I also want to get this.
<div id='div2'>
</div>
</article>
答案 0 :(得分:0)
您可以使用
获取以下兄弟文本following-sibling::text()
以便在文字
之后获取所有 em//em/following-sibling::text()[1]
同样适用于 p 标记,然后加入
string-join(em/following-sibling::text()[1] | p/following-sibling::text()[1] , ',')
我希望这可以提供帮助!