diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-08-19 11:17:01 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-08-19 11:17:01 +0200 |
commit | 4127fcc6d2266c26afc037a5d02d64b7f86df163 (patch) | |
tree | 9edf7cb029d5cf64a00373614b4205e84f5ed7c8 /src | |
parent | 1f2bf08018de022890025618094326bd6556997d (diff) | |
download | ee-python-4127fcc6d2266c26afc037a5d02d64b7f86df163.tar.gz ee-python-4127fcc6d2266c26afc037a5d02d64b7f86df163.tar.bz2 ee-python-4127fcc6d2266c26afc037a5d02d64b7f86df163.tar.xz ee-python-4127fcc6d2266c26afc037a5d02d64b7f86df163.zip |
digikey:
o Checking that the URL changed after clicking a button.
o Click the accept cookie button if found after navigating.
Diffstat (limited to 'src')
-rw-r--r-- | src/ee/digikey/__init__.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/ee/digikey/__init__.py b/src/ee/digikey/__init__.py index b46ba85..e624db9 100644 --- a/src/ee/digikey/__init__.py +++ b/src/ee/digikey/__init__.py @@ -305,6 +305,7 @@ class DigikeyClient(object): form_input, form_button = find_form() if not form_input or not form_button: self.driver.get(self.baseurl) + self._accept_cookies() form_input, form_button = find_form() @@ -312,7 +313,13 @@ class DigikeyClient(object): raise EeException("Could not find form") form_input.send_keys(query) + + old_url = self.driver.current_url form_button.click() + new_url = self.driver.current_url + + if old_url == new_url: + raise EeException("Selenium error: clicked the button but the browser didn't navigate.") page = self.driver.page_source @@ -331,12 +338,18 @@ class DigikeyClient(object): self.on_download("Downloading {}".format(url)) self.driver.get(url) + self._accept_cookies() src = self.driver.page_source self.cache.save(cache_key, src) return src + def _accept_cookies(self): + cookie_blocker = self._find_first_visible("//div[@class='cookie-wrapper']//a[contains(@class, 'button')]") + if cookie_blocker is not None: + cookie_blocker.click() + def get_for_product_url(self, url, product_number): return self._req(url, "product-{}".format(product_number)) |