fixed the TARGET_VERSION variable. is now actually evaluated at execution time so the correct chromedriver for your version of chrome is being downloaded... + some refactorings
This commit is contained in:
parent
9cd00ce07f
commit
2d2401caa5
|
@ -30,8 +30,8 @@ driver.get('https://distilnetworks.com')
|
||||||
Needs to be done before importing from selenium package
|
Needs to be done before importing from selenium package
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import undetected_chromedriver
|
import undetected_chromedriver as uc
|
||||||
undetected_chromedriver.install()
|
uc.install()
|
||||||
from selenium.webdriver import Chrome
|
from selenium.webdriver import Chrome
|
||||||
driver = Chrome()
|
driver = Chrome()
|
||||||
driver.get('https://distilnetworks.com')
|
driver.get('https://distilnetworks.com')
|
||||||
|
@ -40,10 +40,11 @@ driver.get('https://distilnetworks.com')
|
||||||
|
|
||||||
#### the customized way ####
|
#### the customized way ####
|
||||||
```python
|
```python
|
||||||
import undetected_chromedriver
|
import undetected_chromedriver as uc
|
||||||
|
|
||||||
#specify chromedriver version to download and patch
|
#specify chromedriver version to download and patch
|
||||||
undetected_chromedriver.TARGET_VERSION = 78
|
#this did not work correctly until 1.2.1
|
||||||
|
uc.TARGET_VERSION = 78
|
||||||
|
|
||||||
# or specify your own chromedriver binary to patch
|
# or specify your own chromedriver binary to patch
|
||||||
undetected_chromedriver.install(
|
undetected_chromedriver.install(
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -19,7 +19,7 @@ from setuptools import setup
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='undetected-chromedriver',
|
name='undetected-chromedriver',
|
||||||
version='1.2',
|
version='1.2.1',
|
||||||
packages=['undetected_chromedriver'],
|
packages=['undetected_chromedriver'],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'selenium',
|
'selenium',
|
||||||
|
|
|
@ -29,9 +29,8 @@ from selenium.webdriver import ChromeOptions as _ChromeOptions
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
_DL_BASE = "https://chromedriver.storage.googleapis.com/"
|
|
||||||
TARGET_VERSION = 81
|
TARGET_VERSION = 81
|
||||||
__is_patched__ = 0
|
__IS_PATCHED__ = 0
|
||||||
|
|
||||||
|
|
||||||
class Chrome:
|
class Chrome:
|
||||||
|
@ -97,19 +96,23 @@ class ChromeOptions:
|
||||||
|
|
||||||
|
|
||||||
class ChromeDriverManager(object):
|
class ChromeDriverManager(object):
|
||||||
|
|
||||||
installed = False
|
installed = False
|
||||||
selenium_patched = False
|
selenium_patched = False
|
||||||
target_version = TARGET_VERSION
|
target_version = None
|
||||||
|
|
||||||
|
DL_BASE = "https://chromedriver.storage.googleapis.com/"
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, executable_path=None, target_version=None, *args, **kwargs):
|
def __init__(self, executable_path=None, target_version=None, *args, **kwargs):
|
||||||
|
|
||||||
_platform = sys.platform
|
_platform = sys.platform
|
||||||
|
self.target_version = TARGET_VERSION
|
||||||
if target_version:
|
if target_version:
|
||||||
self.__class__.target_version = target_version
|
self.target_version = target_version
|
||||||
self._base = base_ = "chromedriver{}"
|
self._base = base_ = "chromedriver{}"
|
||||||
|
|
||||||
exe_name = self._base
|
exe_name = self._base
|
||||||
|
|
||||||
if _platform in ('win32',):
|
if _platform in ('win32',):
|
||||||
exe_name = base_.format(".exe")
|
exe_name = base_.format(".exe")
|
||||||
if _platform in ('linux',):
|
if _platform in ('linux',):
|
||||||
|
@ -170,7 +173,7 @@ class ChromeDriverManager(object):
|
||||||
if not self.target_version
|
if not self.target_version
|
||||||
else f"LATEST_RELEASE_{self.target_version}"
|
else f"LATEST_RELEASE_{self.target_version}"
|
||||||
)
|
)
|
||||||
return urlopen(_DL_BASE + path).read().decode()
|
return urlopen(self.__class__.DL_BASE + path).read().decode()
|
||||||
|
|
||||||
|
|
||||||
def fetch_chromedriver(self):
|
def fetch_chromedriver(self):
|
||||||
|
@ -185,7 +188,7 @@ class ChromeDriverManager(object):
|
||||||
if os.path.exists(self.executable_path):
|
if os.path.exists(self.executable_path):
|
||||||
return self.executable_path
|
return self.executable_path
|
||||||
urlretrieve(
|
urlretrieve(
|
||||||
f"{_DL_BASE}{ver}/{base_.format(f'_{self.platform}')}.zip",
|
f"{self.__class__.DL_BASE}{ver}/{base_.format(f'_{self.platform}')}.zip",
|
||||||
filename=zip_name,
|
filename=zip_name,
|
||||||
)
|
)
|
||||||
with zipfile.ZipFile(zip_name) as zf:
|
with zipfile.ZipFile(zip_name) as zf:
|
||||||
|
@ -211,7 +214,7 @@ class ChromeDriverManager(object):
|
||||||
binary.seek(-len(line), 1)
|
binary.seek(-len(line), 1)
|
||||||
line = b" var key = '$azc_abcdefghijklmnopQRstuv_';\n"
|
line = b" var key = '$azc_abcdefghijklmnopQRstuv_';\n"
|
||||||
binary.write(line)
|
binary.write(line)
|
||||||
__is_patched__ = 1
|
__IS_PATCHED__ = 1
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
Loading…
Reference in New Issue