New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using a proxy per page with Puppeteer #1948
Comments
@tomgallagher Yeah but there's no answer |
Not to changing them on the fly, but if you only want to do it every 1000 requests, just count and then So try:
or some variant. I agree the docs for this are non-existent. |
@tomgallagher Thanks bro |
No problem. You might as well tell everyone what worked if you have a moment. There's a more detailed discussion of proxies at #678. |
Dupe of #678 |
@tomgallagher Thanks for the answer but seems to only work without the quotes |
I also need it. |
I need it, too. |
Thanks, I need too. |
I also need it. |
try this PuppeteerUtil.useProxy |
@xiyuan-fengyu use |
you are welcome |
You can use https://github.com/gajus/puppeteer-proxy to set proxy either for entire page or for specific requests only, e.g. import puppeteer from 'puppeteer';
import {
createPageProxy,
} from 'puppeteer-proxy';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const pageProxy = createPageProxy({
page,
proxyUrl: 'http://127.0.0.1:3000',
});
await page.setRequestInterception(true);
page.once('request', async (request) => {
await pageProxy.proxyRequest(request);
});
await page.goto('https://example.com');
})(); To skip proxy simply call Using puppeteer-proxy |
Hi Nicolas, I have also been looking for a proxy solution when using Puppeteer. One of the easiest solutions I found is using API proxy services. The basic example will look like this: import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
const url = 'https://proxybot.io/api/......?url=https://example.com';
await page.goto(url);
})(); Every page will be opened through random proxy 😉 |
It's possible with puppeteer-page-proxy. First install it:
Then require it: const useProxy = require('puppeteer-page-proxy'); Using it is easy; await useProxy(page, 'http://127.0.0.1:8000'); If you want a different proxy for each request,then you can simply do this: await page.setRequestInterception(true);
page.on('request', req => {
useProxy(req, 'socks5://127.0.0.1:9000');
}); Then if you want to be sure that your page's IP has changed, you can look it up; const data = await useProxy.lookup(page);
console.log(data.ip); It supports http, https, socks4 and socks5 proxies, and it also supports authentication if that is needed: const proxy = 'http://login:pass@127.0.0.1:8000' Repository: |
—————————————————————————————————————————————— |
@Cuadrix when I try to request a https site it gives me invalid browser request. |
Hello,
I need to use multiple proxy and change let's say every 1000 page.goto() requests.
Is there a way to do this with puppeteer/chromium ?
Thank you !
The text was updated successfully, but these errors were encountered: