Python 仅从xpath scrapy中提取一部分

Python 仅从xpath scrapy中提取一部分,python,xpath,scrapy,Python,Xpath,Scrapy,我想用xpath从网页中提取信息,但我得到的信息是错误的。在下面的代码中,我想得到100: <div class="pricing"> <p class="pricePerUnit"> <p class="pricePerMeasure"> £0.64 <abbr title="per">/</abbr> 100 有什么帮助吗?您可以尝试下面的XPath表达式来获得“100” //p[@class="pricePer

我想用xpath从网页中提取信息,但我得到的信息是错误的。在下面的代码中,我想得到
100

<div class="pricing">
 <p class="pricePerUnit">
  <p class="pricePerMeasure">
  £0.64
  <abbr title="per">/</abbr>
  100

有什么帮助吗?

您可以尝试下面的
XPath
表达式来获得
“100”

//p[@class="pricePerMeasure"]/text()[last()]

另外,我假设只有两个文本节点(
“£0.64”
“100”
),而您刚刚错过了结束标记…

您不能拆分结果,然后获取最后一个元素吗

prices_mesure3 = response.xpath('//p[@class="pricePerMeasure"]/text()').extract()[0].split()[-1]

Xpath支持节点索引,因此您可以将
[last()]
[2]
添加到Xpath中:

In: response.xpath('//p[@class="pricePerMeasure"]/text()[last()]').extract_first()
Out: u'\n  100 '

你能在HTML中添加结束标记吗?你能帮我解决另一个问题吗@Granitosaurus拜托@uzumaki_鸣人当然,还有什么问题?这是问题:
In: response.xpath('//p[@class="pricePerMeasure"]/text()[last()]').extract_first()
Out: u'\n  100 '