f = urllib2.urlopen("http://cuiqingcai.com/1319.html") print f.getcode() # 状态码 print f.geturl() # 实际得到网页所属的url print f.info() # 得到meta information print f.read() # 网页内容
一些例子
HTTP 验证
1 2 3 4 5 6 7 8 9 10 11
import urllib2 # Create an OpenerDirector with support for Basic HTTP Authentication... auth_handler = urllib2.HTTPBasicAuthHandler() auth_handler.add_password(realm='PDQ Application', uri='https://mahler:8092/site-updates.py', user='klem', passwd='kadidd!ehopper') opener = urllib2.build_opener(auth_handler) # ...and install it globally so it can be used with urlopen. urllib2.install_opener(opener) urllib2.urlopen('http://www.example.com/login.html')
近期评论