1
votes

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

1

1 Answers

1
votes

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())