如何 select a 属性 inside a span, using XPath selectors?

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

我正在尝试 select 使用 XPath selectors 的公司地址,以便我稍后可以将其插入我的 Scrapy 蜘蛛中。所以,我的目标是提取地址,在本例中只是 'Address 123'。我现在必须遵循 XPath selector:

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

我得到的输出如下:

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

谁能帮我select'Address 213'?? html代码如下图所示。

HTML code

使用text()提取元素的文本:

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

Example xpather

要提取文本 地址 123,您需要使用 text(),如下所示:

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