|
| 1 | +import platform |
1 | 2 | import random |
| 3 | +import subprocess |
| 4 | +import sys |
2 | 5 | import time |
3 | 6 |
|
4 | 7 | import undetected_chromedriver as uc |
|
8 | 11 | from selenium.webdriver.support import expected_conditions as EC |
9 | 12 | from selenium.webdriver.support.ui import WebDriverWait |
10 | 13 |
|
11 | | -uc.install() |
12 | | - |
| 14 | +print('This will open one chrome driver to test if everything works as expected.\n') |
| 15 | + |
| 16 | +print('Getting Chrome Driver...') |
| 17 | + |
| 18 | +OSNAME = platform.system() |
| 19 | + |
| 20 | +""" |
| 21 | +Getting Chrome version code has been taken from |
| 22 | +https://github.com/yeongbin-jo/python-chromedriver-autoinstaller |
| 23 | +Thanks goes to him. |
| 24 | +""" |
| 25 | +if OSNAME == 'Linux': |
| 26 | + with subprocess.Popen(['chromium-browser', '--version'], stdout=subprocess.PIPE) as proc: |
| 27 | + version = proc.stdout.read().decode('utf-8').replace('Chromium', '').strip() |
| 28 | + version = version.replace('Google Chrome', '').strip() |
| 29 | +elif OSNAME == 'Darwin': |
| 30 | + process = subprocess.Popen( |
| 31 | + ['/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', '--version'], stdout=subprocess.PIPE) |
| 32 | + version = process.communicate()[0].decode( |
| 33 | + 'UTF-8').replace('Google Chrome', '').strip() |
| 34 | +elif OSNAME == 'Windows': |
| 35 | + process = subprocess.Popen( |
| 36 | + ['reg', 'query', 'HKEY_CURRENT_USER\\Software\\Google\\Chrome\\BLBeacon', '/v', 'version'], |
| 37 | + stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, stdin=subprocess.DEVNULL |
| 38 | + ) |
| 39 | + version = process.communicate()[0].decode('UTF-8').strip().split()[-1] |
| 40 | +else: |
| 41 | + print('{} OS is not supported.'.format(OSNAME)) |
| 42 | + sys.exit() |
| 43 | + |
| 44 | +major_version = version.split('.')[0] |
| 45 | + |
| 46 | +uc.TARGET_VERSION = major_version |
13 | 47 |
|
14 | | -print('This will open one chrome driver to test if everything works as expected.') |
| 48 | +uc.install() |
15 | 49 |
|
16 | 50 | driver = None |
17 | 51 |
|
|
0 commit comments