This commit is contained in:
unknown 2021-02-04 12:15:22 +01:00
parent de55331c53
commit 2e2047dc91
2 changed files with 23 additions and 24 deletions

View File

@ -86,7 +86,9 @@ class Chrome:
)
instance.execute_cdp_cmd(
"Network.setUserAgentOverride",
{"userAgent": original_user_agent_string.replace("Headless", ""),},
{
"userAgent": original_user_agent_string.replace("Headless", ""),
},
)
if emulate_touch:
instance.execute_cdp_cmd(
@ -103,7 +105,6 @@ class Chrome:
class ChromeOptions:
def __new__(cls, *args, **kwargs):
if not ChromeDriverManager.installed:
ChromeDriverManager(*args, **kwargs).install()
@ -232,10 +233,10 @@ class ChromeDriverManager(object):
@staticmethod
def random_cdc():
cdc = random.choices(string.ascii_lowercase, k=26)
cdc[-6: -4] = map(str.upper, cdc[-6: -4])
cdc[-6:-4] = map(str.upper, cdc[-6:-4])
cdc[2] = cdc[0]
cdc[3] = '_'
return ''.join(cdc).encode()
cdc[3] = "_"
return "".join(cdc).encode()
def patch_binary(self):
"""

View File

@ -76,8 +76,10 @@ def find_chrome_executable():
for item in os.environ.get("PATH").split(os.pathsep):
for subitem in ("google-chrome", "chromium", "chromium-browser"):
candidates.add(os.sep.join((item, subitem)))
if 'darwin' in sys.platform:
candidates.update(["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"])
if "darwin" in sys.platform:
candidates.update(
["/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"]
)
else:
for item in map(
os.environ.get, ("PROGRAMFILES", "PROGRAMFILES(X86)", "LOCALAPPDATA")
@ -94,8 +96,9 @@ def find_chrome_executable():
class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
__doc__ = """\
__doc__ = (
"""\
--------------------------------------------------------------------------
NOTE:
Chrome has everything included to work out of the box.
@ -103,7 +106,9 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
any customizations MAY lead to trigger bot migitation systems.
--------------------------------------------------------------------------
""" + selenium.webdriver.remote.webdriver.WebDriver.__doc__
"""
+ selenium.webdriver.remote.webdriver.WebDriver.__doc__
)
_instances = set()
@ -315,7 +320,7 @@ class Chrome(selenium.webdriver.chrome.webdriver.WebDriver):
def __exit__(self, exc_type, exc_val, exc_tb):
self.service.stop()
#threading.Timer(self.factor, self.service.start).start()
# threading.Timer(self.factor, self.service.start).start()
time.sleep(self.delay)
self.service.start()
@ -327,7 +332,7 @@ class Patcher(object):
url_repo = "https://chromedriver.storage.googleapis.com"
def __init__(
self, target_path="./chromedriver", force=False, version_main: int = 0
self, target_path="./chromedriver", force=False, version_main: int = 0
):
if not IS_POSIX:
if not target_path[-4:] == ".exe":
@ -374,14 +379,10 @@ class Patcher(object):
:return: version string
:rtype: LooseVersion
"""
path = (
"/"
+ (
"latest_release"
if not self.version_main
else f"latest_release_{self.version_main}"
).upper()
)
path = "/latest_release"
if self.version_main:
path += f"_{self.version_main}"
path = path.upper()
logger.debug("getting release number from %s" % path)
return LooseVersion(urlopen(self.url_repo + path).read().decode())
@ -414,7 +415,7 @@ class Patcher(object):
os.makedirs(os.path.dirname(self.target_path), mode=0o755)
except OSError:
pass
with zipfile.ZipFile(self.zipname, mode='r') as zf:
with zipfile.ZipFile(self.zipname, mode="r") as zf:
zf.extract(self.exename)
os.rename(self.exename, self.target_path)
os.remove(self.zipname)
@ -497,9 +498,6 @@ class Patcher(object):
linect += 1
return linect
class ChromeOptions(selenium.webdriver.chrome.webdriver.Options):
pass