I have this program that check a website, and I want to know how can I check it via proxy in Python...
this is the code, just for example
while True:
try:
h = urllib.urlopen(website)
break
except:
print '['+time.strftime('%Y/%m/%d %H:%M:%S')+'] '+'ERROR. Trying again in a few seconds...'
time.sleep(5)
Python 3 is slightly different here. It will try to auto detect proxy settings but if you need specific or manual proxy settings, think about this kind of code:
Refer also to the relevant section in the Python 3 docs
Here example code guide how to use urllib to connect via proxy:
For http and https use:
more proxies can be added similarly
usage
Don't use any proxies (in case of links within network)
Use proxies authentication via username and password
By default,
urlopen
uses the environment variablehttp_proxy
to determine which HTTP proxy to use:If you instead want to specify a proxy inside your application, you can give a
proxies
argument tourlopen
:Edit: If I understand your comments correctly, you want to try several proxies and print each proxy as you try it. How about something like this?