简体   繁体   English

Puppeteer: 接受多个带有 cookie 横幅的网站中的所有 cookie

[英]Puppeteer: Αccept all cookies in multiple websites with cookie banner

I create a script with Node.js and Puppeteer that loads multiple sites like (site A, B, C etc).我使用 Node.js 和 Puppeteer 创建了一个脚本,用于加载多个站点,例如(站点 A、B、C 等)。 I want to find all the cookies that site uses.The problem is, that some sites have a Cookie Banner to accept or decline.我想找到该站点使用的所有 cookie。问题是,有些站点有一个 cookie 横幅来接受或拒绝。 If you accept the banner the website adds some extra cookies.如果您接受横幅,网站会添加一些额外的 cookie。

So to capture all that cookies is there a general solution to accept all the different banners or to set some initial parameter on header of the initial request to inform the site that I accept all that cookies?因此,要捕获所有 cookie,是否有一个通用的解决方案来接受所有不同的横幅或在初始请求的标头上设置一些初始参数以通知站点我接受所有这些 cookie?

Here is an example of a site with Cookie Bannner initial set 6 cookies and if you accept the banner the total cookies are 48.这是一个带有 Cookie Bannner 初始设置 6 个 cookie 的站点的示例,如果您接受该横幅,则总 cookie 为 48。

https://siteimprove.com/en/gdpr/who-gdpr-affects-and-whose-data-is-protected/ https://siteimprove.com/en/gdpr/who-gdpr-affects-and-whose-data-is-protected/

I need a general solution.我需要一个通用的解决方案。 Because I have a list of websites.因为我有一个网站列表。

Unfortunately, there is no standard way to do this.不幸的是,没有标准的方法可以做到这一点。 Because there is no standard for "cookie banners".因为“cookie 横幅”没有标准。 If your list of websites isn't terribly large, your best bet is to figure out what the cookie is for each site, store them systematically, and use the appropriate cookies based on the domain being navigated.如果您的网站列表不是特别大,最好的办法是弄清楚每个网站的 cookie 是什么,系统地存储它们,并根据所导航的域使用适当的 cookie。

UPDATE: see the puppeteer docs here on how to add cookies to your request: https://pptr.dev/#?product=Puppeteer&version=v5.4.0&show=api-pagecookiesurls更新:请参阅此处的 puppeteer 文档,了解如何将 cookie 添加到您的请求中: https ://pptr.dev/#?product=Puppeteer&version=v5.4.0&show=api-pagecookiesurls

您可以使用 cookie 横幅的标识符: https : //www.fanboy.co.nz/fanboy-cookiemonster.txt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM