Skip to content

Instantly share code, notes, and snippets.

@miraris
Last active June 1, 2019 13:49
Show Gist options
  • Save miraris/1827e5f98967af691d4b66526aa026c8 to your computer and use it in GitHub Desktop.
Save miraris/1827e5f98967af691d4b66526aa026c8 to your computer and use it in GitHub Desktop.
Simple ES6 function to get an array of proxy objects, ready to be plugged into axios
const got = require("got");
const regex = /(?<host>[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})\:?(?<port>[0-9]{1,5})?/;
const getProxy = () =>
got("http://spys.me/proxy.txt").then(({ body }) =>
body
.split("\n")
.filter(val => regex.test(val))
.map(val => {
const {
groups: { host, port }
} = regex.exec(val);
return {
host,
port
};
})
);
getProxy().then(console.log);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment