菜比之路

走菜比的路,让大牛说去吧
  博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

【python】获取指定网页上的所有超级链接

Posted on 2016-09-08 15:59  毕加索的ma  阅读(1959)  评论(0编辑  收藏  举报
# -*- coding: utf-8 -*-
import urllib2
import re

#connect to a URL
website = urllib2.urlopen("http://www.baidu.com")
#read html code
html = website.read()
#use re.findall to get all the links
links = re.findall('"((http|ftp)s?://.*?)"', html)  ###".*?"任意匹配
print links