Last time I wrote a tutorial on downloading Python web pages. Today I want to talk to you about another library:Python urllib
Many Web pages can be processed using the urllib standard library. Next I will share the urllib content that I usually use:
1 If you want to add Chinese characters in the URL request and encode the corresponding Chinese characters, you can use:
Urllib. Quote ('encode string ')
2. If you do not want to be blocked by an IP address when requesting a webpage from the other party, you need to use a proxy at this time.UrllibProxy is relatively simple:
Proxies = {'http': 'proxy ip '}
Opener = urllib. fancyurlopener (proxies)
F = opener. Open ("http://www.python.org ")
F. Read ()
3. If you need some parameters in get, encode the input parameters.
Params = urllib. urlencode ({'spam': 1, 'eggs ': 2, 'bacon': 0 })
F = urllib. urlopen ("http://www.xx.com/query? % S "% Params)
Print F. Read ()
For more information about urllib, use the help command.
ArticleLink:Http://www.cnpythoner.com/post/pythonurllib.htmlReprinted and retained. Thank you!