python的urllib2模块获取网页内容


import urllib2
#直接请求url
response = urllib.urlopen('http://www.baidu.com')
#获取状态码,如200
print response.getcode()
#打印网页源码
print response.read()