Python正则表多行匹配
Python正则表多行匹配
一、总结
一句话总结:
加个标志参数:re.DOTALL:data['a']=re.findall(r'<h1 class = "postTitle">(.*?)</h1>',response.text,re.re.DOTALL)
加个标志参数:re.S:data['a']=re.findall(r'<h1 class = "postTitle">(.*?)</h1>',response.text,re.S)
二、Python正则表多行匹配
转自或参考:正则表达式匹配多行的三个方法(Python)
https://blog.csdn.net/qq_39241986/article/details/100036180
方法一:
加个标志参数:re.DOTALL
方法二:
加个标志参数:re.S
测试代码:
data={} # 获取彩票数据 data['a']=re.findall(r'<h1 class = "postTitle">(.*?)</h1>',response.text,re.S) print(data['a'])
['\n\t\t\t\n<a id="cb_post_title_url" class="postTitle2 vertical-middle" href="https://www.cnblogs.com/Renyi-Fan/p/13264726.html">\n <span>python超简单实用爬虫操作---1、爬虫介绍</span>\n \n\n\n</a>\n\n\t\t']