Sep-01-2021, 02:20 PM
(This post was last modified: Sep-01-2021, 02:20 PM by DeaD_EyE.
Edit Reason: fixed inconsistency
)
Some improvements + error corrections + info about urls..
import random import sys import time import requests # Take the right protocol # "testurl.com" is not a valid URL # "http://testurl.com" is valid url = "https://python-forum.io/thread-34789.html" # set headers # this was missing in the code example and this was causing the # NameError headers = {} # Proxies must also start with http:// or https:// proxies = [ "http://173.68.59.131:3128", "http://64.124.38.139:8080", "http://69.197.181.202:3128", ] random.shuffle(proxies) result = None for proxy in proxies: try: response = requests.get( url, headers=headers, proxies={"https": proxy}, timeout=3 ) except (requests.ReadTimeout, requests.ConnectionError): print("Got timeout", file=sys.stderr) continue except Exception as e: print("Contact the programer", repr(e), file=sys.stderr) else: print(response.status_code, file=sys.stderr) # be a good shell citizen # don't print debugging data to stdout if response.status_code == 200: result = response.text # break out of loop if result was found break if result is None: print("No success", file=sys.stderr) else: time.sleep(2) print(result)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!