From 6caf8fe3d09b24c095ff88daea001ae1312aac5a Mon Sep 17 00:00:00 2001 From: Leon Date: Tue, 29 Nov 2022 11:16:45 +0100 Subject: [PATCH 1/4] add additional search path for x32 and updated 'port' description --- undetected_chromedriver/__init__.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/undetected_chromedriver/__init__.py b/undetected_chromedriver/__init__.py index 66214e1..7ab24be 100644 --- a/undetected_chromedriver/__init__.py +++ b/undetected_chromedriver/__init__.py @@ -152,8 +152,10 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver): If not specified, make sure the executable's folder is in $PATH port: int, optional, default: 0 - port you would like the service to run, if left as 0, a free port will be found. - + port to be used by the chromedriver executable, this is NOT the debugger port. + leave it at 0 unless you know what you are doing. + the default value of 0 automatically picks an available port. + enable_cdp_events: bool, default: False :: currently for chrome only this enables the handling of wire messages @@ -805,7 +807,7 @@ def find_chrome_executable(): ) else: for item in map( - os.environ.get, ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA") + os.environ.get, ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA", "PROGRAMW6432") ): if item is not None: for subitem in ( From b11a720f3e099b8766ce59716fae179c0601fb7a Mon Sep 17 00:00:00 2001 From: Leon Date: Tue, 29 Nov 2022 14:25:25 +0100 Subject: [PATCH 2/4] Update example.py --- undetected_chromedriver/example/example.py | 28 ++++++++++++++-------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/undetected_chromedriver/example/example.py b/undetected_chromedriver/example/example.py index afc2880..2b37482 100644 --- a/undetected_chromedriver/example/example.py +++ b/undetected_chromedriver/example/example.py @@ -1,10 +1,12 @@ import time -from selenium.webdriver.remote.webdriver import By -import selenium.webdriver.support.expected_conditions as EC # noqa -from selenium.webdriver.support.wait import WebDriverWait - import undetected_chromedriver as uc +import selenium.webdriver.support.expected_conditions as EC # noqa + +from selenium.webdriver.remote.webdriver import By +from selenium.webdriver.support.wait import WebDriverWait +from selenium.common.exceptions import WebDriverException + driver = uc.Chrome() @@ -28,13 +30,13 @@ driver.execute_script( let container = document.querySelector('#rso'); let el = document.createElement('div'); el.style = 'width:500px;display:block;background:red;color:white;z-index:999;transition:all 2s ease;padding:2em;font-size:1.5em'; - el.textContent = "these are excluded from offical support ;)"; + el.textContent = "Excluded from support...!"; container.insertAdjacentElement('afterBegin', el); """ ) -time.sleep(2) +time.sleep(2) # never use this. this is for demonstration purposes only for item in results_container.children("a", recursive=True): print(item) @@ -60,8 +62,6 @@ inp_search.clear() inp_search.send_keys("hot girls\n") # \n as equivalent of ENTER body = driver.find_element(By.TAG_NAME, "body") -# inp_search = driver.find_element(By.XPATH, '//input[@title="Search"]') -# inp_search.send_keys("hot nude girls") # \n as equivalent of ENTER body.find_elements(By.XPATH, '//a[contains(text(), "Images")]')[0].click_safe() # you can't reuse the body from above, because we are on another page right now @@ -71,7 +71,7 @@ image_search_body = WebDriverWait(driver, 5).until( ) # gets all images and prints the src -print("getting image data, hold on...") +print("getting image sources data, hold on...") for item in image_search_body.children("img", recursive=True): @@ -105,8 +105,16 @@ for idx in range(1, 10): # skip the first handle which is our original window print("opening ", USELESS_SITES[idx]) driver.switch_to.window(driver.window_handles[idx]) - driver.get(USELESS_SITES[idx]) + # because of geographical location, (corporate) firewalls and 1001 + # other reasons why a connection could be dropped we will use a try/except clause here. + try: + driver.get(USELESS_SITES[idx]) + except WebDriverException as e: + print(( + 'webdriver exception. this is not an issue in chromedriver, but rather ' + 'an issue specific to your current connection. message:', e.args)) + continue for handle in driver.window_handles[1:]: driver.switch_to.window(handle) From cb3d91064a0089048b56fc34943c3a8c0bd2c1d1 Mon Sep 17 00:00:00 2001 From: Leon Date: Tue, 29 Nov 2022 14:25:42 +0100 Subject: [PATCH 3/4] Update example.py --- undetected_chromedriver/example/example.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/undetected_chromedriver/example/example.py b/undetected_chromedriver/example/example.py index 2b37482..71be2fa 100644 --- a/undetected_chromedriver/example/example.py +++ b/undetected_chromedriver/example/example.py @@ -29,7 +29,7 @@ driver.execute_script( """ let container = document.querySelector('#rso'); let el = document.createElement('div'); - el.style = 'width:500px;display:block;background:red;color:white;z-index:999;transition:all 2s ease;padding:2em;font-size:1.5em'; + el.style = 'width:500px;display:block;background:red;color:white;z-index:999;transition:all 2s ease;padding:1em;font-size:1.5em'; el.textContent = "Excluded from support...!"; container.insertAdjacentElement('afterBegin', el); From f13a0c15314e1cf3fe99bc720b29223dec240d98 Mon Sep 17 00:00:00 2001 From: Leon Date: Tue, 29 Nov 2022 14:27:57 +0100 Subject: [PATCH 4/4] Update setup.py include example file --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index bf688f1..4e7f0dd 100644 --- a/setup.py +++ b/setup.py @@ -44,6 +44,7 @@ setup( "requests", "websockets", ], + package_data={"undetected_chromedriver": [os.path.join("example", "example.py")]}, url="https://github.com/ultrafunkamsterdam/undetected-chromedriver", license="GPL-3.0", author="UltrafunkAmsterdam",