Python: GET Webpage Content
Suppose you want to GET a webpage's content. The following code does it:
# -*- coding: utf-8 -*- # python # example of getting a web page from urllib import urlopen print urlopen("http://xahlee.info/python/python_index.html").read()
Sometimes in working with HTML pages, you need to create links. In URL, certain chars need to be encoded. For example,
http://example.com/~xah needs to be
http://example.com/%7Exah. Basically, any reserved chars
! * ' ( ) ; : @ & = + $ , / ? # [ ] when not used for special purposes such as CGI parameters, needs to be encoded by its hexadecimal. For example,
~ has hexadecimal
7e, so it needs to be encoded as
In Python, the
quote function does it.
unquote reverses it.
# -*- coding: utf-8 -*- # python from urllib import quote print quote("~joe's home page") print 'http://www.google.com/search?q=' + quote("ménage à trois")
- Python: HTTP POST Using Library “requests”
- Python: Web Crawler
- URL Percent Encoding and Unicode
- Linux: Download Website: wget, curl, HEAD, GET
- Perl: GET Web Page Content
If you have a question, put $5 at patreon and message me.