I want to use proxy lists but I'm not sure how to do this:
Check if first connection is established (it does not matter it is the first proxy IP or not), run something and then close the program and exit, else go to the next proxy.
This is my code that loops over all proxies:
import requests
from Proxy_List_Scrapper import Scrapper, Proxy, ScrapperException
ALL = 'ALL'
scrapper = Scrapper(category=ALL, print_err_trace=False)
# Get ALL Proxies According to your Choice
data = scrapper.getProxies()
n = 0
while True:
n += 1
try:
for item in data.proxies:
# Enter a proxy IP address and port.
url = 'http://api.ipify.org'
# Send a GET request to the url and pass the proxy as a parameter.
page = requests.get(url, proxies={"http": f'{item.ip}:{item.port}', "https": f'{item.ip}:{item.port}'})
# Prints the content of the requested url.
print(f'proxy is {item.ip}:{item.port} and content is {page.text}')
except requests.exceptions.ProxyError:
print(f'error #{n}')