Merge branch '3.2.0' of http://github.com/ultrafunkamsterdam/undetected-chromedriver into 3.2.0
This commit is contained in:
commit
e4d75cbdd0
1
setup.py
1
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",
|
||||
|
|
|
@ -149,8 +149,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
|
||||
|
@ -802,7 +804,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 (
|
||||
|
|
|
@ -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()
|
||||
|
@ -27,14 +29,14 @@ 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.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);
|
||||
|
||||
"""
|
||||
)
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in New Issue