DEV Community

MarkPy
MarkPy

Posted on • Edited on

Proxyscrape Get Proxy List by Using Python

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

1. Proxyscrape Installation

pip install proxyscrape
Enter fullscreen mode Exit fullscreen mode

2. getting united states proxy

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

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
Enter fullscreen mode Exit fullscreen mode

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

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

Print the host and the port:

print(f"{proxy.host}:{proxy.port}")
#output
103.105.49.53:80
Enter fullscreen mode Exit fullscreen mode

3. Getting proxies list

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

syntax:

collector.get_proxies()
Enter fullscreen mode Exit fullscreen mode

Example

proxy = collector.get_proxies({'country': 'france'})  
print(proxy)
Enter fullscreen mode Exit fullscreen mode

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')]
Enter fullscreen mode Exit fullscreen mode

References:
proxyscrape Library

PyTutorial

Top comments (0)