In this tutorial, We'll learn how to get a fresh proxy by using Proxyscrape library.

1. Proxyscrape Installation

pip install proxyscrape

2. getting united states proxy

in the first example we'll get a proxy of united states

Example:

    
import proxyscrape
collector = proxyscrape.create_collector('my-collector', 'http')  # Create a collector for http resources
proxy = collector.get_proxy({'country': 'united states'})  # Retrieve a united states proxy
print(proxy) # print the proxy

    

So first we have imported the library, then created our collector, finally, chose the country, now let's see the output.

output


Proxy(host='103.105.49.53', port='80', code='us', country='united states', anonymous=True, type='http', source='free-proxy-list')

print the host and the port:


print(f"{proxy.host}:{proxy.port}")

output


103.105.49.53:80

3. Getting proxy by type

syntax


collector.get_proxy({'type': 'https'})  
#type (http, https, socks4, socks5, …)

Example:

in this example, we'll get a https proxy


proxy = collector.get_proxy({'type': 'https'})  

output


Proxy(host='200.255.122.170', port='8080', code='br', country='brazil', anonymous=True, type='https', source='ssl-proxy')

as you can see, we have got a random https proxy.

4. Getting proxies list

in this part, we'll get a France list of proxies

syntax


collector.get_proxies()

Example


proxy = collector.get_proxies({'country': 'france'})  

print(proxy)

output


[Proxy(host='51.158.123.35', port='8811', code='fr', country='france', anonymous=True, type='http', source='anonymous-proxy'), 
Proxy(host='195.154.233.187', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='195.154.51.252', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='195.154.52.142', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='212.83.140.218', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='51.158.123.250', port='8811', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='195.154.47.113', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='51.158.98.121', port='8811', code='fr', country='france', anonymous=True, type='https', source='anonymous-proxy'), 
Proxy(host='159.8.114.34', port='8123', code='fr', country='france', anonymous=True, type='http', source='free-proxy-list'), 
Proxy(host='195.154.56.105', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='195.154.52.142', port='3838', code='fr', country='france', anonymous=True, type='https', source='anonymous-proxy'), 
Proxy(host='195.154.56.105', port='3838', code='fr', country='france', anonymous=True, type='https', source='anonymous-proxy'), 
Proxy(host='51.158.98.121', port='8811', code='fr', country='france', anonymous=True, type='http', source='free-proxy-list'), 
Proxy(host='51.158.123.250', port='8811', code='fr', country='france', anonymous=True, type='https', source='anonymous-proxy'), 
Proxy(host='51.158.119.88', port='8811', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='163.172.120.204', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='46.218.155.194', port='3128', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='51.15.156.144', port='3838', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list'), 
Proxy(host='51.158.165.18', port='8811', code='fr', country='france', anonymous=True, type='https', source='free-proxy-list')]

Recommended Posts:

Currency conversion in python

English today is not an art to be mastered it's just a tool to use to get a result