Reputation: 1589
I have the following HTML code:
<html>
<span class='whatever'>
<div @id='xyz'>
"text1"
"text2" <=== I am trying to extract this text
</div>
</span>
</html>
Is it possible to write an xpath that points to the node that is text2? If yes, then I can extract via .text (python).
Upvotes: 0
Views: 107
Reputation: 4869
You can extract complete text
with //div[@id='xyz']/text()
XPath and then get required text with
text.split('\n')[-1]
Upvotes: 1
Reputation: 142
That really depends on what type of parser you are using for your html. Your html parser would provide you with something like a inner html or inner text node get module. You can use that and if you only want text2 you can use regular expressions or something other to filter the text out.
There is another method that if html is also written by you. Then you can enclose the text2 with span tag and directly get it.
Upvotes: 1