automatic-azure•4y ago
userAgent in different crawlers
How to set the userAgent in different crawlers?
5 Replies
continuing-cyan•4y ago
In different crawlers? Or in different requests for the same crawler?
automatic-azureOP•4y ago
like cheerio, puppeteer. the apis are not always the same.
for my case i need to differentiate between cheerio ua and puppeteer ua.
You should use
preNavigationHooks for it:
https://crawlee.dev/api/puppeteer-crawler/interface/PuppeteerCrawlerOptions#preNavigationHooks
example for Cheerio:
for Puppeteer you should use page object.
you can try to use setExtraHTTPHeaders() (inside preNavigationHooks too):
https://pptr.dev/next/api/puppeteer.page.setextrahttpheaders
example:
or just add it to request object:
{url, headers: { 'user-agent': '[UA-STRING]' } }automatic-azureOP•4y ago
@Alexey Udovydchenko this works like a charm - thanks!