Proxy Manager
Project description
This module loads and returns proxies for easy use with requests.
Installation
This module is available via pip:
$ pip install proxymngr
Basic Usage
proxies.txt:
00.11.222.33:4444 55.66.777.88:9999:username:password
test.py:
from proxymngr import ProxyManager
proxy_manager = ProxyManager('proxies.txt')
random_proxy = proxy_manager.random_proxy()
print(random_proxy) # { 'http':'http://...', 'https':'https://...' }
first_proxy = proxy_manager.next_proxy()
print(first_proxy.get_dict()) # { 'http':'http://00.11.222.33:4444', 'https':'https://00.11.222.33:4444' }
second_proxy = proxy_manager.next_proxy()
print(second_proxy.get_dict()) # { 'http':'http://username:password@55.66.777.88:9999', 'https':'https://username:password@55.66.777.88:9999' }
third_proxy = proxy_manager.next_proxy()
print(third_proxy.get_dict()) # { 'http':'http://00.11.222.33:4444', 'https':'https://00.11.222.33:4444' }
Documentation
Proxy File Format
Proxies in proxy files must have one of the following formats:
ip:port
or
ip:port:username:password
These can be combined and alternated.
ProxyManager
ProxyManager(proxy_file_path)
Returns a new ProxyManager instance given the path to a proxy file.
Parameters
string - File path to the proxy
Returns
ProxyManager - ProxyManager with proxies loaded
Example
from proxymngr import ProxyManager
proxy_manager = ProxyManager('proxies.txt')
ProxyManager.random_proxy
ProxyManager.random_proxy()
Returns a random proxy of those loaded into the proxy manager
Parameters
none
Returns
Proxy - Random proxy as a Proxy object
Example
random_proxy = proxy_manager.random_proxy()
print(random_proxy.get_dict()) # { 'http':'http://...', 'https':'https://...' }
ProxyManager.next_proxy
ProxyManager.next_proxy()
Returns proxies consecutively. Thread-safe. Loops continuously through available proxies, with wrapping.
Parameters
none
Returns
Proxy - Next proxy as a Project object
Example
first_proxy = proxy_manager.next_proxy()
print(first_proxy.get_dict()) # { 'http':'http://00.11.222.33:4444', 'https':'https://00.11.222.33:4444' }
Documentation for the Proxy object
Proxy.get_dict
Proxy.get_dict()
Parameters
none
Returns
dict - Proxy as a dict in the form { 'http':'http://...', 'https':'https://...' } for use with requests
Example
```py proxy = proxy_manager.next_proxy() proxy_dict = first_proxy.get_dict() print(proxy_dict.get_dict()) # { ‘http’:’http://00.11.222.33:4444’, ‘https’:’https://00.11.222.33:4444’ }
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.