auto-proxy
v1.0.21
Published
Never care about proxylists again!
Downloads
6
Readme
auto-proxy
Never care about proxies again!
AutoProxy is a nodejs module that ships with web-scrapers out-of-the-box!
That means you don't have to spend hours goog'ling proxysites.
Just fire up AutoProxy and let it search the proxies for you.
However if you've still got one of these old-style IP:PORT
lists on your 16MB flash-drive,
AutoProxy can handle that too.
Installation
npm i --save auto-proxy
Usage
const AutoProxy = require('auto-proxy');
Just create a new instance using .new()
and pass the path to it
// Parameters:
// 1st -> How many requests a proxy can handle before autoproxy swaps it
// 2nd -> Options
// 3rd -> Path to your proxylist
// 4th -> Whether to disable the crawler or not
AutoProxy.new(25, {}, '/path/to/proxy.list', false).then(function(proxy){
//PROFIT!
});
Note: This list must be in this format:
IP:PORT
IP:PORT
...
Just want to check if your list works?
The "normal" API
The normal API is completely Promise/A+ based. If you don't like this you can use the __simple__
API.
.new(interval, options, localProxylist, disableCrawling)
Creates an auto-proxy instance
// The interval describes how many requests a proxy may handle before
// a new one will be used
//
// The options object takes as less or many options as you like, but you have to define it (empty object)
//
// Here you see how a full config looks like, and what the default options are
AutoProxy.new(25, {
enableLogging: false, //Wether to interact with the user or not
autoRefresh: false, //If enabled auto-proxy will reload the proxies as soon as there are no more in the pool.
//Please note that this may take up to a few minutes depending on your internet speed.
//While debugging this may seem like you program is stuck if you disable $enableLogging
reLoop: false //After there are no more proxies in the pool, just start over.
//You'd have to call .refillProxies() to crawl for new proxies
__simple__: { // The __simple__ API. For usage scroll down :)
reLoop: true // Works like the reloop option of auto-proxy.
// To refill, you'd have to call .refillProxies() and __simple__.refresh() afterwards
}
}).then(function(proxy) { //This proxy object is your instance
... // Use your instance
});
.refillProxies()
Loads new proxies from various proxylists
proxy.refillProxies().then(function(){
// Proxies are now refilled.
// Use them!
...
});
.forceNext()
Force-switch to the next proxy. Resets the interval counter
proxy.forceNext().then(function(){
// Proxy is switched!
// Use it!
...
});
.blockCurrent()
Blocks the current proxy, so that it won't be reLoop'ed or used again
proxy.blockCurrent().then(function(){
// Proxy is blocked and switched!
// Use it!
...
});
.getCurrent(ignoreUsage)
Get the current proxy
// Respects the proxy interval
proxy.getCurrent().then(function(ip) {
console.log(`The ip is ${ip}`);
});
// Ignores the proxy interval
proxy.getCurrent(true).then(function(ip) {
console.log(`The ip is ${ip}`);
});
.getPrefixedCurrent(ignoreUsage)
Works like .getCurrent()
but prefixes the IP with http://
.
The __simple__
API
The simple API is completely synchronous and does not refresh/re-scrape automatically.
.init()
Initializes the caches and prepares for usage
You should call this in the AutoProxy.new().then()
callback.
.refresh()
This method will copy all proxies from the normal API into a seperate cache used only by __simple__
.
You can clear this cache using .__simple__.resetCache()
.next()
Jumps to the next proxy and resets the interval
.get()
Returns the current proxy (repecting the interval)
.block()
Blocks the current proxy, so that it won't be reLoop'ed or used again
So how do i handle an empty proxy pool when i'm using the __simple__
API?
Glad you asked :)
The __simple__
API throws a ProxiesEmptyException
when there are no more proxies.
Just catch it, load new proxies and refresh the cache. VOILA!
let ip = null;
try {
ip = proxy.__simple__.get();
} catch (e) {
proxy.refillProxies().then(function(){
proxy.__simple__.refresh();
ip = proxy.__simple__.get();
});
}
I just want to check if my proxies work!
No problem!
AutoProxy.new(1, {}, '/path/to/list.txt', true).then(function(proxy) {
require('fs').writeFileSync('checked_proxies.txt', JSON.stringify(proxy.proxyList));
});