May 2017
Beginner to intermediate
220 pages
5h 2m
English
Sometimes it's necessary to access a website through a proxy. For example, Hulu is blocked in many countries outside the United States as are some videos on YouTube. Supporting proxies with urllib is not as easy as it could be. We will cover requests for a more user-friendly Python HTTP module that can also handle proxies later in this chapter. Here's how to support a proxy with urllib:
proxy = 'http://myproxy.net:1234' # example string proxy_support = urllib.request.ProxyHandler({'http': proxy})opener = urllib.request.build_opener(proxy_support)urllib.request.install_opener(opener) # now requests via urllib.request will be handled via proxy
Here is an updated version of the download function to integrate this:
def download(url, ...
Read now
Unlock full access