[英]find the appropriate regular expression
Can you help me to find the right Regular expression to extract ( Margaux
or Saint-Julien
) in each time of this 2 pages: 您能帮我在
Margaux
页的每次中找到正确的正则表达式来提取( Margaux
或Saint-Julien
):
in page 1 : Margaux, Rouge
第1页 :
Margaux, Rouge
in page 2 : 2ème Vin, Saint-Julien, Rouge
在第2页中 :
2ème Vin, Saint-Julien, Rouge
my code : 我的代码:
item ["appelation"] = res.select('.//div[@class="pro_col_right"]/div[@class="pro_blk_trans"]/div[@class="pro_blk_trans_titre"]/text()').re(r'\s*\w+\-\w+\-\w+|\w+\-\w+|\[^Rouge,Blanc]')
My regular expression couldn't find Margaux but it extracts Saint-Julien !! 我的正则表达式找不到Margaux,但它提取了Saint-Julien!
Not sure why you need this but suppose s
is your html file then this regex will find what you look for.. 不知道为什么您需要它,但是假设
s
是您的html文件,那么此正则表达式将找到您想要的东西。
import re
m = re.search(r"\<div\ class=\"pro_blk_trans_titre\"\>(.*)\</div\>", s)
print(m.group(1).strip().encode("utf8"))
# page1: b'Margaux, Rouge'
# page2: b'2\xc3\xa8me Vin, Saint-Julien, Rouge'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.