jmquintana79
8/2/2017 - 9:44 AM

Get html of website using a proxy server

Get html of website using a proxy server

## read webpage using a proxy server
def read_ulr_with_proxy(url,proxy_url, proxy_port):
    import urllib.request as web
    try:
        proxy_handler = web.ProxyHandler({'http':proxy_url+':'+proxy_port})
        new_opener = web.build_opener(proxy_handler)
        page = new_opener.open(url)
        print('INFO: Success reading "%s"'%url)
        return page.read()
    except IOError as e:
        print('ERROR reading: %s'%url)
        print(str(e))
        return None