在 <p> 标签内获取 <a > 标签内的文本
Getting text within <a > tag inside <p> tag
您好,我一直在尝试获取 div - p 标签中的所有文本部分,直到 hr 标签,所以有人给了这个 xpath
//div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]/text()
效果很好,但这会忽略 p 标签中 <.a> 标签中的文本部分
还有什么想法可以获取该文本吗?
<div class="entry">
<p> some text</p>
<p> some text2</p>
<p> some text3</p>
<p> some text4
<a href='somelink'> this text here i want to get through xpath</a>
some text5
</p>
<hr>(up to this hr tag)
<p> some text5</p>
<hr>
<p> some text6</p>
</div>
一种方法可能是 //div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]//text()
,但我可能更喜欢简单地 select 元素 //div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]
并使用字符串值。
你可以简单的根据xpath拉取数据
//div[@class="entry"]/p[0]
//div[@class="entry"]/p[1]
//div[@class="entry"]/p[2]
//div[@class="entry"]/p[3]
//div[@class="entry"]/p[4]
//div[@class="entry"]/p[5]
您好,我一直在尝试获取 div - p 标签中的所有文本部分,直到 hr 标签,所以有人给了这个 xpath
//div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]/text()
效果很好,但这会忽略 p 标签中 <.a> 标签中的文本部分 还有什么想法可以获取该文本吗?
<div class="entry">
<p> some text</p>
<p> some text2</p>
<p> some text3</p>
<p> some text4
<a href='somelink'> this text here i want to get through xpath</a>
some text5
</p>
<hr>(up to this hr tag)
<p> some text5</p>
<hr>
<p> some text6</p>
</div>
一种方法可能是 //div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]//text()
,但我可能更喜欢简单地 select 元素 //div[@class="entry"]/*[not(preceding-sibling::hr | self::hr)]
并使用字符串值。
你可以简单的根据xpath拉取数据
//div[@class="entry"]/p[0]
//div[@class="entry"]/p[1]
//div[@class="entry"]/p[2]
//div[@class="entry"]/p[3]
//div[@class="entry"]/p[4]
//div[@class="entry"]/p[5]