难度范围内的XPATH - Scrapy

时间:2018-05-21 18:56:15

标签: xpath web-scraping scrapy

我使用Scrapy并基于XPATH选择器编写脚本。我尝试搜索XPATH语法来收集两个值:price和EAN编号(500.02,08043687312822)。价格:500,2和EAN:08043687312822

<div class="emProductPrice">
  <span itemprop="offers" itemscope="" itemtype="http://example.com/Offer">
    <span 
itemprop="price" content="500.02">500,02</span>&nbsp;hrywna<meta itempr\
op="priceCurrency" content="PLN">
    <meta itemprop="gtin14" 
content="08043687312822">
    <link itemprop="itemCondition" 
href="http://example.com/NewCondition">
    <l\ink itemprop="availability" href="http://example.com/InStock">
  </span> 
</div>

我尝试编写类似于//div[@class="emProductPrice"/span/span/text()的语法,但我只得到:&amp; nbsp。我需要500,02例如

这是怎么回事?请帮忙。

1 个答案:

答案 0 :(得分:1)

你需要:

price = response.xpath('//span[@itemprop="price"]/@content').extract_first()
ean = response.xpath('//meta[@itemprop="gtin14"]/@content').extract_first()