Import Urllib
def main ():
Url= ' http://www.qq.com '
Url1=urllib.urlopen (URL)
# print Url1.read () Printing source code
# print Url1.info () header information
# print Url1.getcode () Status code
# print Url1.geturl () printing URLs
# print Url1.code status code
# print Url1.fileno () file Object
# Print URL1.FP
# Print Url1.headers header information
# print Url1.next () <! DOCTYPE html>
# print Url1.url printing URLs
# Urllib.urlretrieve (Url,path) writes to the hard disk
# print Urllib.quote (URL) encoding
# print Urllib.quote_plus (URL)
# print Urllib.unquote (URL) decoding
#get Way
# Url2=urllib.urlencode ({' span ': 1, ' eggs ': 2, ' bacon ': 0})
# Print Url2
# Print Urllib.urlopen (' http://python.org/query?%s '% (URL2)). Read ()
#post Way
# Url2=urllib.urlencode ({' span ': 1, ' eggs ': 2, ' bacon ': 0})
# Print Url2
# Print Urllib.urlopen (' Http://python.org/query ', (URL2)). Read ()
#http Agent
proxies={' http: ': ' http://proxy.example.com:8080/'}
Opener=urllib. Fancyurlopener (proxies)
F=opener.open (' http://www.python.org ')
Print F.read ()
Main ()
Python urllib Basic Learning