美文网首页
正则提取网页内容

正则提取网页内容

作者: Wudi1 | 来源:发表于2017-01-11 10:33 被阅读0次

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

     这里只是记录一下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>

    相关文章

      网友评论

          本文标题:正则提取网页内容

          本文链接:https://www.haomeiwen.com/subject/gwalbttx.html