Sign in to follow this  
SWAT

Tutorial Python Proxy Switcher basic tutorial

Recommended Posts

Webp-net-gifmaker.gif

[hide]

 

[align=center]Hi everyone,

I noticed there are a lot of people wanting to learn python and so I thought I'd share this with you guys so you can learn/study the script.

 

 

You can use this to help with scraping or just for testing out a proxy list to see which ones work. It's mainly for learning though so it doesnt do anything fancy. Let me know if you need any help and like if its useful.[/align]

[align=center]

#we need to import a few things to make it work first
from lxml.html import fromstring
from itertools import cycle
import requests

#This sets a list of proxies. You can get this from many different sites.
PROXY_LIST = ['1.10.240.135:8080',
'101.109.142.5:8080',
'177.124.16.178:45817',
'101.109.110.221:8080']

#creates a 'pool' of proxies which is based on the list so it isn't one after another. This helps if you have many sequential proxies.
proxy_pool = cycle(PROXY_LIST)
#sets an empty list of working proxies which we will populate later
working_proxies = []
#sets the url you want to visit - this one just returns an IP address
url = 'https://www.canihazip.com/s'

#goes through each proxy in the PROXY_LIST - you could set the second part (where len(PROXY_LIST) is) to a big number if you wanted to keep testing.
for i in range(0,len(PROXY_LIST)):
#Get the next proxy from the pool
proxy = next(proxy_pool)
print("Request #%d"%i)
try:
    #print response from website
    response = requests.get(url, proxies={"http": proxy, "https": proxy})
    print("working proxy at:"+str(response.content))
    working_proxies.append(proxy)
except:
    #if it doesnt work throw a connect error
    print("Connnection error")

#lists all working proxies, it converts the list to a set so it only shows unique values.
print("The working proxies are:"+ str(set(working_proxies)))

[/hide]

[/align]

[align=center]


[/align]

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this