-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathvivaldi_ex.py
executable file
·65 lines (54 loc) · 2.37 KB
/
vivaldi_ex.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env python3
# origin: https://stackoverflow.com/questions/59644818/how-to-initiate-a-chromium-based-vivaldi-browser-session-using-selenium-and-pyth
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import getopt
from os import getenv
import sys, time, datetime
if getenv('OS') != None :
homedir = getenv('USERPROFILE').replace('\\', '/')
chromedriver = 'chromedriver.exe'
browser = (r'{}\AppData\Local\Vivaldi\Application\vivaldi.exe'.format(getenv('USERPROFILE'))) # per-user
executable_path = r'{}\Downloads\{}'.format(getenv('USERPROFILE'), chromedriver)
else:
homedir = getenv('HOME')
chromedriver = 'chromedriver'
browser = '/usr/bin/vivaldi'
# place driver into individual directory to avoid collisions between chromium and vivaldi
executable_path = '{}/Downloads/vivaldi/{}'.format(homedir, chromedriver)
# NOTE:
# Vivaldi 2.2.1388.37
# is reported to be running chrome 71:
# Current browser version is 71.0.3578.98 with binary path /usr/bin/vivaldi
# which requires
# ChromeDriver 2.46
# this combination selenium opens visible browser window but fails to navigate it anywhere
# the Vivaldi 4.1.2369 is running chrome 92.0.4515.134
options = Options()
options.add_argument('start-maximized')
options.binary_location = browser
# additional options
options.add_argument('--window-size=1920, 1080')
options.add_argument('--disable-extensions')
# options.add_argument('--headless')
options.add_argument('--disable-gpu')
#options.add_argument('--disable-dev-shm-usage')
options.add_argument('--no-sandbox')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--allow-insecure-localhost')
options.add_argument('--allow-running-insecure-content')
options.add_argument('--disable-browser-side-navigation')
options.add_argument('--enable-javascript')
options.add_argument('--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:72.0) Gecko/20100101 Firefox/72.0"')
driver = webdriver.Chrome( executable_path = executable_path, options = options)
url = 'https://qna.habr.com'
try:
driver.get(url = url)
time.sleep(1)
print('navigated to {}'.format(driver.current_url))
except Exception as e:
# selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
print(e)
finally:
driver.close()
driver.quit()