直接来自Py3k文档:http
://docs.python.org/dev/py3k/library/urllib.request.html#examples
import urllib.request# Create an OpenerDirector with support for Basic HTTP Authentication...auth_handler = urllib.request.HTTPBasicAuthHandler()auth_handler.add_password(realm='PDQ Application', uri='https://mahler:8092/site-updates.py', user='klem', passwd='kadidd!ehopper')opener = urllib.request.build_opener(auth_handler)# ...and install it globally so it can be used with urlopen.urllib.request.install_opener(opener)urllib.request.urlopen('http://www.example.com/login.html')
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)