正则提取网页内容

正则匹配网页所需要的网页内容

 这里只是记录一下findall方法所抓取的想要的内容。

. 匹配除换行符以外的任意单个字符
* 匹配前面的子表达式零次或者是多次
? 匹配前面的子表达式零次或一次,或指明一个非贪婪限定符(匹配最近一个满足条件的字符)
.*? 非贪婪匹配任意多个任意字符
加上re.S是全文匹配

 具体请看以下实例

import re

text = """Sxchaoinfo@EgithubE
    xchaoinfo@wechat
    xchaoinfo@zhihuE"""

pattern = r'S.*?E'
pattern2 = r'S.*E'
pattern3 = r'S(.*?)E'
result1 = re.findall(pattern, text)
result2 = re.findall(pattern, text, re.S)
result3 = re.findall(pattern2, text)
result4 = re.findall(pattern2, text, re.S)
result5 = re.findall(pattern3, text)
result6 = re.findall(pattern3, text, re.S)
print result1--------->  ['Sxchaoinfo@E']
print result2--------->  ['Sxchaoinfo@E']
print result3--------->  ['Sxchaoinfo@EgithubE']
print result4--------->  ['Sxchaoinfo@EgithubE\n    xchaoinfo@wechat\n    xchaoinfo@zhihuE']
print result5--------->  ['xchaoinfo@']
print result6--------->  ['xchaoinfo@']

 匹配的结果已经在代码中贴出。

</p>[xss](javascript:alert(1))<p>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容