我正在努力让我的刮刀变得隐秘。 对我来说最后一个障碍是浏览器语言,事实上无论参数是什么我都无法修改。
我可以修改语言的HTTP标头,但不能修改浏览器语言,我在playwirght浏览器的系统文件中搜索但没有参数。
这是我的代码的最小部分:
const { firefox } = require('playwright-extra');
const stealth = require('puppeteer-extra-plugin-stealth')();
firefox.use(stealth);
firefox.launch({
headless: false,
args: ['--lang=fr-FR'],
}).then(async browser => {
const context = await browser.newContext({
locale: 'fr-FR',
timezoneId: 'Europe/Paris',
geolocation: { latitude: 48.8566, longitude: 2.3522 },
});
const page = await context.newPage();
await page.setExtraHTTPHeaders({
'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
});
console.log('Navigating to test browser language settings...');
const url = 'https://www.browserscan.net/';
await page.goto(url, { waitUntil: 'networkidle0' });
await page.screenshot({ path: 'browser-language.png', fullPage: true });
console.log('Done! Check browser-language.png for results.');
await browser.close();
})
通过启动 playwright 实例而不使用
await browser.close();
我能够浏览参数并找到: 语言参数图像
正是这个参数需要更改,但我在文档中找不到任何有关它的内容。
有人知道吗?
对于那些正在寻找解决方案的人,我将在下面与您分享:
我没有加载所有转义插件,而是一一加载它们,以便我可以将所需的语言设置传递给 navigator.languages 插件。
剩下的就是设置 http headers 和 时区。
而且我们在大多数网站上都无法被检测到:)
const { firefox } = require('playwright-extra');
const evasions1 = require('puppeteer-extra-plugin-stealth/evasions/iframe.contentWindow')();
const evasions2 = require('puppeteer-extra-plugin-stealth/evasions/media.codecs')();
const evasions3 = require('puppeteer-extra-plugin-stealth/evasions/navigator.hardwareConcurrency')();
const evasions4 = require('puppeteer-extra-plugin-stealth/evasions/navigator.languages')({ languages: ['fr','fr-FR','en-US','en'] })
const evasions5 = require('puppeteer-extra-plugin-stealth/evasions/navigator.permissions')();
const evasions6 = require('puppeteer-extra-plugin-stealth/evasions/navigator.plugins')();
const evasions7 = require('puppeteer-extra-plugin-stealth/evasions/navigator.vendor')();
const evasions8 = require('puppeteer-extra-plugin-stealth/evasions/navigator.webdriver')();
const evasions9 = require('puppeteer-extra-plugin-stealth/evasions/sourceurl')();
const evasions10 = require('puppeteer-extra-plugin-stealth/evasions/user-agent-override')();
const evasions11 = require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor')();
const evasions12 = require('puppeteer-extra-plugin-stealth/evasions/window.outerdimensions')();
const evasions13 = require('puppeteer-extra-plugin-stealth/evasions/defaultArgs')();
firefox.use(evasions1);
firefox.use(evasions2);
firefox.use(evasions3);
firefox.use(evasions4);
firefox.use(evasions5);
firefox.use(evasions6);
firefox.use(evasions7);
firefox.use(evasions8);
firefox.use(evasions9);
firefox.use(evasions10);
firefox.use(evasions11);
firefox.use(evasions12);
firefox.use(evasions13);
(async () => {
const browser = await firefox.launch({ headless: false });
const browserContext = await browser.newContext({
extraHTTPHeaders: {
'Accept-Language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
},
timezoneId: 'Europe/Paris' // Choisir un fuseau horaire, ici Paris
});
const page = await browserContext.newPage();
await page.goto("https://www.browserscan.net/",{ waitUntil: 'networkidle0' });
await page.screenshot({ path: 'stealth-persistent-context.png', fullPage: true });
})();
这是一个概念验证代码,对于正在寻找解决方案的人来说,你当然可以进行优化。