mirror of
https://github.com/bellingcat/auto-archiver.git
synced 2026-06-13 13:48:28 +03:00
Add some code to attempt to click the cookies banners on various websites
This commit is contained in:
@@ -72,6 +72,8 @@ class CookieSettingDriver(webdriver.Firefox):
|
|||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f'Failed on fb accept cookies.', e)
|
logger.warning(f'Failed on fb accept cookies.', e)
|
||||||
|
|
||||||
|
|
||||||
# now get the actual URL
|
# now get the actual URL
|
||||||
super(CookieSettingDriver, self).get(url)
|
super(CookieSettingDriver, self).get(url)
|
||||||
if self.facebook_accept_cookies:
|
if self.facebook_accept_cookies:
|
||||||
@@ -79,7 +81,17 @@ class CookieSettingDriver(webdriver.Firefox):
|
|||||||
close_button = self.find_element(By.XPATH, "//div[@role='dialog']//div[@aria-label='Close']")
|
close_button = self.find_element(By.XPATH, "//div[@role='dialog']//div[@aria-label='Close']")
|
||||||
if close_button:
|
if close_button:
|
||||||
close_button.click()
|
close_button.click()
|
||||||
|
else:
|
||||||
|
|
||||||
|
# for all other sites, try and use some common button text to reject/accept cookies
|
||||||
|
for text in ["Refuse non-essential cookies", "Decline optional cookies", "Reject additional cookies", "Accept all cookies"]:
|
||||||
|
try:
|
||||||
|
accept_button = self.find_element(By.XPATH, f"//*[contains(translate(text(), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), '{text.lower()}')]")
|
||||||
|
if accept_button:
|
||||||
|
accept_button.click()
|
||||||
|
break
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Webdriver:
|
class Webdriver:
|
||||||
|
|||||||
Reference in New Issue
Block a user