userAgent in different crawlers
How to set the userAgent in different crawlers?
5 Replies
foreign-sapphire•3y ago
In different crawlers? Or in different requests for the same crawler?
optimistic-goldOP•3y ago
like cheerio, puppeteer. the apis are not always the same.
for my case i need to differentiate between cheerio ua and puppeteer ua.
inland-turquoise•3y ago
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:
eastern-cyan•3y ago
or just add it to request object:
{url, headers: { 'user-agent': '[UA-STRING]' } }
optimistic-goldOP•3y ago
@Alexey Udovydchenko this works like a charm - thanks!