문제

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?

도움이 되었습니까?

해결책

You can just use: .//div[@id="_parent"]//text() to fetch all text node children of the selected node. You can test it here.

다른 팁

If you want all data of an element (so, all string nodes), you can also use

data(.//div[@id="_parent"])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top