You can just use: .//div[@id="_parent"]//text()
to fetch all text node children of the selected node. You can test it here.
XPath recursive children selection
문제
I'm using scrapy to extract data from a web site, but I have a problem with the XPath selector, assuming i have this HTML code:
<div id="_parent">
Hi!
<p>I am a child!</p>
<span class="someclass">I am a <b>span</b> child!</span>
</div>
what I get:
I am a child
I am a child!
what I should get:
Hi!
I am a child!
I am a span child!
The XPath I am using is the following: .//div[@id="_parent"]//*/text() I know this is because is not a direct children of the #_parent div but how can I recursively get all the children?
해결책
다른 팁
If you want all data of an element (so, all string nodes), you can also use
data(.//div[@id="_parent"])
제휴하지 않습니다 StackOverflow