你能帮我写一个以下字符串的表达式:
Multi 3620 IDS; 17120846;9;12.04.2018
14:09:02;8,531;;pH;24,1;°C;Temp;AR;60%;;SenTix 940; C171412055;
如何使用正则表达式获取数字8,531
?
是否有任何规则可以在特定数量的分号后提取数字?
谢谢
答案 0 :(得分:3)
就个人而言,我甚至不会使用正则表达式:
import re
s = "Multi 3620 IDS; 17120846;9;12.04.2018 \n14:09:02;8,531;;pH;24,1;°C;Temp;AR;60%;;SenTix 940; C171412055;"
print(s.split(";")[4])
但如果您必须使用正则表达式(由于某种未知原因),您可以使用以下
(?:[^;]*;){4}([^;]+)
(?:[^;]*;){4}
完全匹配以下4次
[^;]*
匹配除;
以外的任何字符;
按字面意思匹配([^;]+)
将;
除import re
s = "Multi 3620 IDS; 17120846;9;12.04.2018 \n14:09:02;8,531;;pH;24,1;°C;Temp;AR;60%;;SenTix 940; C171412055;"
r = re.compile("(?:[^;]*;){4}([^;]+)")
m = r.match(s)
if m:
print(m.group(1))
之外的任何字符一次或多次捕获到捕获组1 class PaginationTestSpider(scrapy.Spider):
name = 'pagination'
start_urls = ['http://esencjablog.pl/page/58']
def parse(self, response):
# Find href from next page link
link = response.css('.post_more a.qbutton::attr(href)')
if link:
# Extract href, in this case we can use first because you only need 1
href = link.extract_first()
# just in case the website use relative hrefs
url = response.urljoin(href)
# You may change the callback if you want to use a different method
yield scrapy.Request(url, callback=self.parse)