Skip to content

Instantly share code, notes, and snippets.

@stephonchen
Last active November 28, 2023 23:32
Show Gist options
  • Save stephonchen/7647575d6a2f063a9973f398ef281db8 to your computer and use it in GitHub Desktop.
Save stephonchen/7647575d6a2f063a9973f398ef281db8 to your computer and use it in GitHub Desktop.
puppeteer + tor + polipo
#!/usr/bin/node
// use puppeteer 0.12.0
// since puppeteer has problems in socks5
// use polipo as a http proxy, which parent proxy is tor (localhost:9050)
var time = require('time');
var sleep = require('sleep');
const random_max = 10;
const puppeteer = require('puppeteer');
var sleep_time = getRandomInt(random_max);
function getRandomInt(max) {
return Math.floor(Math.random() * Math.floor(max));
}
async function run() {
// use tor
const browser = await puppeteer.launch({'executablePath': '/usr/bin/chromium-browser', 'args': ['--proxy-server=127.0.0.1:8123']});
const page = await browser.newPage();
const url = 'https://www.google.com/';
page.on('error', err => {
console.log(err)
})
let response = await page.goto(url, {waitUntil: 'networkidle', timeout: 0});
// Do something
const title = await page.title();
console.log(title);
var now = time.Date();
var dt = now.toString();
console.log(dt+","+response.status);
browser.close();
}
run();
@iyyappanpauls
Copy link

how to configure this ip 127.0.0.1:8123 in tor browser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment