Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
410 views
in Technique[技术] by (71.8m points)

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

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

question from:https://stackoverflow.com/questions/65918270/how-to-select-a-property-inside-a-span-using-xpath-selectors

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...