如何检测来自 Puppeteer 的请求? [英] How to detect the request come from Puppeteer?
问题描述
我想知道是否存在网站可以使用它来检测来自 Puppeteer 的请求的标志或标签?
I wonder whether or not exists some flag or tag that the website can use it to detect the request came from Puppeteer?
当我运行基于 Puppeteer 的代码访问目标网站时,我发现该网站似乎知道请求是由 Puppeteer 发出的.
When I ran my code based on Puppeteer to visit the target website, I found that the website seems to know the request was made by Puppeteer.
怎么办?
推荐答案
如果您正在运行 puppeteer 并希望将一些信息传递到网站以捕获您的抓取情况,那么最好的方法是设置自定义用户代理:
If you are running the puppeteer and would like to pass some information to the website to catch your crawling, the best way to do so would be to set a custom user agent:
const browser = await puppeteer.launch({
args: ['--user-agent=hhh'],
});
const page = await browser.newPage();
请参阅此处了解更多信息
反之亦然,如果您拥有一个网站并且想知道访问是真实的还是来自机器人(木偶操作者、抓取工具或其他任何东西),请参阅这个答案 对于其中一些.还有 这个答案
Viceversa, if you own a website and would like to know if the visits are real or from a bot (puppeteer, a scraper, or anything else) see this answer for some of them. Also this answer
这篇关于如何检测来自 Puppeteer 的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!