Last active
November 28, 2023 23:32
-
-
Save stephonchen/7647575d6a2f063a9973f398ef281db8 to your computer and use it in GitHub Desktop.
puppeteer + tor + polipo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to configure this ip 127.0.0.1:8123 in tor browser