Click on Button to accept cookies


#1

Hello!
I would like my crawler to click on the “accept cookies” buttons. This is my code:

var btn = $(“button.js-privacywall-agree.privacy-button.privacy-button-secondary-dark”);
btn.click();

The buttton will be correctly selected but the click doesn’t work…


#2

It looks, that page probably executes some JS script after you click on button.

I recommend click on button save cookies and open page again with previous cookies.
You can do that using:

  1. Set up Cookies persistence to Over all crawlers run.
  2. On the start URL click on the button and enqueue page with new uniqueuKey again using context.enqueuePage({ url: context.request.url, uniqueKey: Match.random() })

or

You can just click on the button in your browser and use a cookie in the crawler. You can check how you can do in this kb article.