For my crawling project, I’m trying to block popups for all sites using selenium and python.
The following chrome_options settings helped me block pop ups for some sites but it is also blocking some sites to load:
chrome_options = Options()
chrome_options.add_argument("--window-size=1920,1080")
chrome_options.add_argument("--start-maximized")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-infobars")
chrome_options.add_argument("--disable-extensions")
chrome_options.add_argument('--disable-notifications')
chrome_options.add_argument("--disable-plugins")
)
chrome_options.add_experimental_option("prefs", {
"profile.default_content_setting_values.cookies": 2,
"profile.default_content_setting_values.javascript": 1,
"profile.managed_default_content_settings.notifications":2,
"profile.managed_default_content_settings.popups":2,
"profile.block_third_party_cookies": True,
"profile.default_content_setting_values.plugins": 1,
})
I tried multiple options and also this for these two sites to load but they load blank on using block all cookies.
"profile.default_content_setting_values.cookies": 2,
"profile.managed_default_content_settings.cookies":1,
"profile.content_settings.exceptions.cookies":{
"https://www.misterspex.de/":{"setting":1},
"https://www.kabum.com.br/":{"setting":1}
How can I create an exception for some sites while blocking cookies for the rest using chrome_options or using something within the code?