我正在尝试使用 puppeteer 抓取超市网站。尽管我希望能够以编程方式进行,但我可以使用 chrome 网络爬虫插件来抓取它。我得到的只是一个空白屏幕,页面上没有加载任何内容。
我已经尝试了网络上的所有提示和技巧,使 puppeteer 操作者无法被检测到,但没有任何效果。见下文,我设置了许多类似于普通浏览器 session 的选项,但似乎没有任何效果。有没有人有任何提示可以帮助我抓取这个网站?
这是我尝试过的代码:
const puppeteer = require('puppeteer');
(async function main() {
try {
const args = [
'--no-sandbox',
'--disable-setuid-sandbox',
'--disable-infobars',
'--window-position=0,0',
'--ignore-certifcate-errors',
'--ignore-certifcate-errors-spki-list',
'--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3312.0 Safari/537.36"'
];
const options = {
args,
headless: false,
ignoreHTTPSErrors: true,
userDataDir: './tmp',
dumpio: true,
devtools: true
};
//launch the browser
const browser = await puppeteer.launch(options);
//open new page
const page = await browser.newPage();
//set the browser viewport
await page.setViewport({
width: 1920,
height: 1080,
});
//set the language to english
await page.setExtraHTTPHeaders({
'Accept-Language': 'en'
});
//set the URL in a variable
const url = 'https://shop.coles.com.au/a/a-national/product/vanish-napisan-gold-pro-oxiaction';
//Go to the page
await page.goto(url, { "waitUntil": "networkidle2" });
//get the title
const productTitle = await page.$eval('span.product-name', el => el.innerText.trim());
//log the title in the console
console.log(productTitle);
} catch (e) {
console.log('our error', e);
}
})();
我还应该尝试什么?
最佳答案
关于node.js - 如何让 puppeteer 操纵者不被发现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57201862/