开发者

Jaxen /text() not working

开发者 https://www.devze.com 2022-12-16 07:23 出处:网络
I have the html: <p> 开发者_如何学运维<a href=\"#\">click here</a> Welcome </p>

I have the html:

<p>
开发者_如何学运维<a href="#">click here</a>
Welcome
</p>

And I just want to retrieve the "Welcome" part using Xpath combined with the Jaxen lib the Xpath I am using is;

//p/text()

Now when I remove the /text() it retrieves;

click here
Welcome

With the /text() added it retrieve null Is there any other way to retrieve everything inside the p tag but excluding any other tags?


From the XML parser point of view, there are multiple text elements to choose from (Welcome and the whitespace preceding and following it), so it doesn't choose any one. You have a few options, mainly stripping the whitespace before parsing or being more specific about the query, like selecting the second most text element:

//p/text()[2]
0

精彩评论

暂无评论...
验证码 换一张
取 消