项目描述
这是基于 webdriver-manager 的项目,本项目使用 淘宝 npm 镜像 来加速下载浏览器驱动,仅适用于 Chrome、Firefox 和 Opera。
依赖
安装
pip install cnpm-webdriver-manager
用法
使用 Chrome
# selenium 3
from selenium import webdriver
from cnpm_webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from cnpm_webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
使用 Firefox
# selenium 3
from selenium import webdriver
from cnpm_webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
# selenium 4
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from cnpm_webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
使用 Opera
# selenium 3
from selenium import webdriver
from selenium.webdriver.chrome import service
from cnpm_webdriver_manager.opera import OperaDriverManager
webdriver_service = service.Service(OperaDriverManager().install())
webdriver_service.start()
driver = webdriver.Remote(webdriver_service.service_url, webdriver.DesiredCapabilities.OPERA)
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome import service
from cnpm_webdriver_manager.opera import OperaDriverManager
webdriver_service = service.Service(OperaDriverManager().install())
webdriver_service.start()
options = webdriver.ChromeOptions()
options.add_experimental_option('w3c', True)
driver = webdriver.Remote(webdriver_service.service_url, options=options)
如果 Opera 浏览器安装在 Windows 系统中,且位置处于 C:/Program Files 或 C:/Program Files (x86) 之外;同时,在所有类 Unix 系统变体以及 Mac 系统中,其安装位置处于 /usr/bin/opera 之外,那么请使用以下代码,
options = webdriver.ChromeOptions()
options.binary_location = "opera.exe 的路径"
driver = webdriver.Remote(webdriver_service.service_url, options=options)
Metadata
Release files for cnpm-webdriver-manager 4.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| cnpm_webdriver_manager-4.0.4.tar.gz | 9.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cnpm_webdriver_manager-4.0.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 24.2 kB
Release files / cnpm_webdriver_manager-4.0.4.tar.gz
| Download URL | cnpm_webdriver_manager-4.0.4.tar.gz |
|---|---|
| Size | 9.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
121006732f60254354efff58928055efed780dccfa60652fc1f7ea4e187128ba
|
|
BLAKE2b-256 checksum How to use checksums |
44551b56c50feb7e0024e5b0168881343e396185fc55376647c18a87a5e86533
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Release files / cnpm_webdriver_manager-4.0.4-py3-none-any.whl
| Download URL | cnpm_webdriver_manager-4.0.4-py3-none-any.whl |
|---|---|
| Size | 15.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6ce442779456bd3dfefe182936c9eeaf4450e25e2dce4f4e8e0d1a05bec1ffb4
|
|
BLAKE2b-256 checksum How to use checksums |
a99526f772d34d8564efca371b893c56cacf3807c91f30e9e4935db9242866ac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.11
|
Security for cnpm-webdriver-manager 4.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.