Accepting cookies dialog or removing it

Author: ThibTripCreated Feb 25, 2021Updated Feb 4, 2025

Problem description

Hello !

I am trying to obtain usable screenshots from many webpages (not just siemens like in the example). Sadly there is always some kind of pop up for cookies which I can't remove. I know how to do it with for instance selenium but I would rather not use any other library then yours. The speed with parallel requests is insane and it's easy to use :tada: !

Is there a way to accept the dialog or just remove it? A generic solution would be best obviously but I am also interested in a domain specific one if this is not possible (since everyone uses different cookies banners...).

Thanks in advance :+1:

image

Code Sample

python
from requests_html import AsyncHTMLSession

asession = AsyncHTMLSession()
url = 'https://www.siemens.de'
r = await asession.get(url)
await r.html.arender(keep_page=True) # "will allow you to interact with the browser page through r.html.page"
screenshot = await r.html.page.screenshot(options={'fullPage':True}) # PNG bytes

# optional (display the page with IPython)  / you can also add 'path':'example.png' to the screenshot options
# to save it on disk
from IPython.display import display_png
display_png(screenshot, raw=True)