python 如何提取网页所有超链接?

import urllib2
import re

website = urllib2.urlopen(http://www.bxwx.org/b/5/5383/)

html = website.read()

links = re.findall('"((http|ftp)s?://.*?)"', html)

print links

raw_input()

我代码这样,不知道为什么一运行就退出了。

参考:http://bbs.chinaunix.net/thread-919021-1-1.html
http://www.oschina.net/code/snippet_782578_14041
http://outofmemory.cn/code-snippet/15549/use-python-regular-url

访问web内容等要用try excpt捕获一下异常,可能访问什么的会有错误返回。

不知道能不能导进去JSOUP,java里用过这个实现

coding=utf-8

"""
提取网页上所有超链接
"""
import urllib2
import BeautifulSoup as bs

html = urllib2.urlopen('http://www.bxwx.org/b/5/5383/').read()
soup = bs.BeautifulSoup(html)
links = soup.findAll('a')
print links