Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/342.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Scrapy:将零件数据存储在一个项目字段中的嵌套标记中_Python_Xpath_Web Scraping_Scrapy - Fatal编程技术网

Python Scrapy:将零件数据存储在一个项目字段中的嵌套标记中

Python Scrapy:将零件数据存储在一个项目字段中的嵌套标记中,python,xpath,web-scraping,scrapy,Python,Xpath,Web Scraping,Scrapy,我有以下问题:我从一个网站上刮取价格,它可以工作,但它只需要逗号前面的数字 示例:当某个东西的价值为“79,90欧元”时,它只会刮去79欧元,而不会刮去90欧元 <span class="price right right10"> € 79, <sup> 90* </sup> </span> 这是我当前的xpath选择器: item['price'] = ''.join(sel.xpath('div[@class=

我有以下问题:我从一个网站上刮取价格,它可以工作,但它只需要逗号前面的数字

示例:当某个东西的价值为“79,90欧元”时,它只会刮去79欧元,而不会刮去90欧元

<span class="price right right10">
    € 79,
    <sup>
    90*
    </sup>
</span>
这是我当前的xpath选择器:

item['price'] = ''.join(sel.xpath('div[@class="waresSum"]/p/span/text()').extract())

关键问题是,您要求的是
span
的直接文本子节点,您需要从
span
元素内部获取所有文本节点:

//div[@class="waresSum"]/p/span//text()
                            HERE^
此外,我将使用过滤掉不需要的字符,只获取数字、
-

$ scrapy shell index.html
In [9]: ''.join(response.xpath('//span//text()').re(r'[0-9,\-]+'))
Out[9]: u'79,90'
$ scrapy shell index.html
In [9]: ''.join(response.xpath('//span//text()').re(r'[0-9,\-]+'))
Out[9]: u'79,90'