python scrapy re正则表达式

推荐一个unicode转换网址http://tool.chinaz.com/Tools/Unicode.aspx

  • re正则表达式
re.findall(u'\u8f6c\u53d1\[(\d+)\]',selector.xpath('//div[not(@class)]/span[1]/a/text()').extract_first())
//提取“评论[11]”中的数字11

re.findall(u'\u8bc4\u8bba\[(\d+)\]',selector.xpath('//div[not(@class)]/span[2]/a/text()').extract_first())
//提取“转发[11]”中的数字11

re.findall(u'\u8d5e\[(\d+)\]',selector.xpath('//div[not(@class)]/span[3]/a/text()').extract_first()) 
//提取“赞[11]”中的数字“11”

re.findall(u'\s(\d+)/',selector.xpath('//input[@type="submit"]/text()').extract_first())
//提取“ 11/150”中的数字“11”(“\s”匹配空格,“/”不需要转义)   

re.findall(u'\u5173\u6ce8\[(\d+)\]',selector.xpath('//div[@class="tip2"]/a[1]/text()').extract_first())
//提取“关注[11]”中的数字“11”

re.findall(u'\u7c89\u4e1d\[(\d+)\]',selector.xpath('//div[@class="tip2"]/a[2]/text()').extract_first())
//提取“粉丝[11]”中的数字“11”

re.findall(u'\u5fae\u535a\[(\d+)\]',selector.xpath('//div[@class="tip2"]/span[@class="tc"]/text()').extract_first())
//提取“微博[11]”中的数字“11

有个要注意的问题是,re.findall()返回的是list数组,若确认list数组合法后,最好采用re.findall()[0]

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值