首页 > 编程语言 > 详细

(转)Python:正则表达式找出网页上所有链接

时间:2014-01-21 17:48:43      阅读:430      评论:0      收藏:0      [点我收藏+]

转自:http://www.linuxany.com/archives/596.html

bubuko.com,布布扣
import re
import urllib
def test(html,rex):
    alist = []
    r = re.compile(rex)
    matchs = r.findall(html)
    if matchs != None:
        for found in matchs:
            if found not in alist:
                alist.append(found)         
    return alist
             
rex = r<a\s*href=\"(.*?)\"
page=urllib.urlopen(http://hi.baidu.com)
html=page.read()
page.close()
 
print test(html,rex)
bubuko.com,布布扣

(转)Python:正则表达式找出网页上所有链接

原文:http://www.cnblogs.com/youthdream/p/3527787.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!