简体   繁体   English

使用正则表达式Scrapy排除多个条件

[英]Exclude more than one condition with regex Scrapy

I´m new with Scrapy 我是Scrapy的新手

I want to exclude two elements in the same item. 我想在同一项目中排除两个元素。 Below I´m excluding "SKU:", I wanna add " sku ". 在下面我不包括“ SKU:”,我想添加“ sku ”。 I didn´t find the way. 我没找到路。

'SKU': ready.xpath(SKU).re_first(r'SKU:\s*(.*)'), # Limpia SKU:

Anny suggestion? 安妮的建议? thanks so much 非常感谢

Not sure what exactly you want, but looks like you talk about regex that can run against both "SKU" and "sku". 不确定您到底想要什么,但是您似乎在谈论可以同时针对“ SKU”和“ sku”运行的正则表达式。 In extract_first you can use python compiled regular expression rather than string, so it could be done like this: extract_first您可以使用python编译的正则表达式而不是字符串,因此可以这样进行:

import re

re_sku = re.compile(r'sku:*\s*(.+)', re.IGNORECASE)

...
'SKU': ready.xpath(SKU).re_first(re_sku),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM