How to select a property inside a span, using XPath selectors?

Viewed 147

I am trying to select the address of a company using XPath selectors, so that I can later insert it in my Spider in Scrapy. So, my goal is to extract the address, in this case only 'Address 123'. I now have to following XPath selector:

> response.xpath('//span[@property="streetAddress"]').get()

The output I get is as follows:

'<span class="partners__info-value" property="streetAddress">Address 123</span>'

Can anybody help me to select only 'Address 213'?? The html code is can be seen in the picture below.

HTML code

2 Answers

Use text() to extract the text of an element:

response.xpath('//span[@property="streetAddress"]/text()')

Example xpather

To extract the text Address 123 you need to use text() as follows:

response.xpath('//span[@class="partners__info-value" and @property="streetAddress"]/text()')
Related