看看官方文档中的如何使用urllib软件包获取Internet资源:
# create a password managerpassword_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()# Add the username and password.# If we knew the realm, we could use it instead of None.top_level_url = "http://example.com/foo/"password_mgr.add_password(None, top_level_url, username, password)handler = urllib.request.HTTPBasicAuthHandler(password_mgr)# create "opener" (OpenerDirector instance)opener = urllib.request.build_opener(handler)# use the opener to fetch a URLopener.open(a_url)# Install the opener.# Now all calls to urllib.request.urlopen use our opener.urllib.request.install_opener(opener)



