简体   繁体   中英

xpath is not working in this node

I am working with scrapy with python.

I have this html node

<div class="comment-right-box">
    <center>
        <h3>
            Call the Seller
        </h3>
    </center>
    <div class="span1">055 176 1262</div>
</div>

I want to get the number inside the span1

I tried this xpath

normalize-space(.//div[@class='comment-right-box']/center/h3[contains(normalize-space(.), 'Call the Seller')]/parent/following-sibling::div[@class='span1']/text())

I got empty result.

what am I doing wrong?

Please don't suggest going directly to the span1 class

There is no parent node. You want the first ancestor:

normalize-space(//div[@class='comment-right-box']
                /center/h3[contains(normalize-space(.), 'Call the Seller')]
                /ancestor::*[1]/following-sibling::div[@class='span1']/text())

Or you could also use ../

normalize-space(//div[@class='comment-right-box']
                /center/h3[contains(normalize-space(.), 'Call the Seller')]
                /../following-sibling::div[@class='span1']/text())

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM