When scraping with Selenium etc., it may not work if the version of WebDriver is different, so I searched for a module that matches the version without permission and summarized it.
pip install chromedriver-autoinstaller
Add to code that executes
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install()
Check if the correct version of chromedriver exists and if not, install the correct version
def install(cwd=False):
"""
Appends the directory of the chromedriver binary file to PATH.
:param cwd: Flag indicating whether to download to current working directory
:return: The file path of chromedriver
"""
def get_chrome_version():
"""
Get installed version of chrome on client
:return: The version of chrome
"""
chromedriver-py It seems to automatically download and install the latest chromedriver binary version
pip install chromedriver-py
Adding from chromedriver_py import binary_path
will assign the Chrome driver path to binary_path
It seems that it will be automatically updated to the latest version
from selenium import webdriver
from chromedriver_py import binary_path # this will get you the path variable
driver = webdriver.Chrome(executable_path=binary_path)
driver.get("http://www.python.org")
assert "Python" in driver.title
ChromeDriver Installer for Python Omitted because it seems difficult to read something
pip install chromedriver_installer \
--install-option="--chromedriver-version=2.10"
The function to install the driver and pass the path like this Simple
Firefox geckodriver-autoinstaller A script that automatically installs geckodriver
pip install geckodriver-autoinstaller
Add ```import geckodriver_autoinstallerto the code you want to use and
geckodriver_autoinstaller.install () ``
Add
from selenium import webdriver
import geckodriver_autoinstaller
geckodriver_autoinstaller.install()
# Check if the current version of geckodriver exists
# and if it doesn't exist, download it automatically,
# then add geckodriver to path
driver = webdriver.Firefox()
driver.get("http://www.python.org")
assert "Python" in driver.title
Check if the correct version of geckodriver exists and if not, install the correct version
def install(cwd=False):
"""
Appends the directory of the geckodriver binary file to PATH.
:param cwd: Flag indicating whether to download to current working directory
:return: The file path of geckodriver
"""
def get_firefox_version():
"""
Get installed version of chrome on client
:return: The version of chrome
"""
pygeckodriver A script that automatically checks every hour for updates to the gecko driver and installs it
pip install pygeckodriver
If you add pygeckodriver import geckodriver_path
, the path of geckodriver will be entered in geckodriver_path
.
from selenium import webdriver
from pygeckodriver import geckodriver_path
bs = webdriver.Firefox(executable_path=geckodriver_path)
bs.get('https://www.pypi.org')
pip install pyderman
import pyderman as driver
#Install FIrefox driver
path = driver.install(browser=driver.firefox)
print('The path of the installed geckodriver driver is: %s' % path)
Downloads the driver for the specified browser and returns the destination path
def install(browser=None, file_directory='./lib/', verbose=True, chmod=True, overwrite=False, version='latest', filename=None, return_info=False):
"""
Downloads the given browser driver, and returns the path it was saved to.
:param browser: The Driver to download. Pass as `pyderman.chrome/firefox`. Default Chrome.
:param file_directory: The directory to save the driver.
:param verbose: If printouts are okay during downloading.
:param chmod: If True, attempt to make the downloaded driver executable.
:param overwrite: If true, overwrite existing drivers of the same version.
:param version: The version to download. Default 'latest'.
:param filename: The filename to save the driver to. Defaults to driver-specific.
:param return_info: If True, return an Object with more download information.
:return: The absolute path of the downloaded driver, or None if something failed.
"""
Edge is experimental code, so it seems better to specify the version
Webdriver Manager for Python Scripts that make it easier to manage drivers for different browsers
pip install webdriver_manager
Until now, I downloaded the driver by hand every time there was an update, and in Chrome I set the path etc. like the following
So far
webdriver.Chrome('/home/user/drivers/chromedriver')
ChromeDriverManager(path=custom_path).install()
Instead
Chrome
from webdriver_manager.chrome import ChromeDriverManager
webdriver.Chrome(ChromeDriverManager().install())
It looks like this Firefox
Firefox
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
IE
IE
from webdriver_manager.microsoft import IEDriverManager
driver = webdriver.Ie(IEDriverManager().install())
Opera
Opera
from webdriver_manager.opera import OperaDriverManager
driver = webdriver.Opera(executable_path=OperaDriverManager().install())
CLI tool for managing web drivers?
pip install webdriver_controller
webdriver_controller [-h] {download,cleanup,list,start} ...
Webdriver controller
positional arguments:
{download,cleanup,list,start}
download Download the Webdriver binary
Remove cleanup Webdriver binaries
list Display a list of downloaded Webdrivers
start Start Selenium
optional arguments:
-h, --help This help message(Original)Show
pip install webdriverdownloader
Firefox
Firedox
from webdriverdownloader import GeckoDriverDownloader
#Install the latest version
gdd = GeckoDriverDownloader()
# v0.20.Install version 0
gdd.download_and_install("v0.20.0")
Chrome
Chrome
from webdriverdownloader import ChromeDriverDownloader
#Install the latest version
gdd = ChromeDriverDownloader()
# v0.20.Install version 0
gdd.download_and_install("v0.20.0")
Opera (based on Chromium)
Opera(Chromium base)
from webdriverdownloader import OperaChromiumDriverDownloader
#Install the latest version
gdd = OperaChromiumDriverDownloader()
# v0.20.Install version 0
gdd.download_and_install("v0.20.0")
webdriverdownloader browser:version
When installing 2.38 of Chrome, the latest version of Firefox, v2.35 of opera
example
webdriverdownloader chrome:2.38 firefox opera:v.2.35
A script that automatically searches and downloads the latest version (or specific version) of the WebDriver binary and puts it in your path Same usage as webdriver downloader at present (2020/3/12)
pip install webdrivermanager
Firefox
Firedox
from webdriverdownloader import GeckoDriverDownloader
#Install the latest version
gdd = GeckoDriverDownloader()
# v0.20.Install version 0
gdd.download_and_install("v0.20.0")
Chrome
Chrome
from webdriverdownloader import ChromeDriverDownloader
#Install the latest version
gdd = ChromeDriverDownloader()
# v0.20.Install version 0
gdd.download_and_install("v0.20.0")
Opera (based on Chromium)
Opera(Chromium base)
from webdriverdownloader import OperaChromiumDriverDownloader
#Install the latest version
gdd = OperaChromiumDriverDownloader()
# v0.20.Install version 0
gdd.download_and_install("v0.20.0")
webdriverdownloader browser:version
If you have installed 2.38 of Chrome, the latest version of Firefox, v2.35 of opera
example
webdriverdownloader chrome:2.38 firefox opera:v.2.35
Recommended Posts