Skip to main content

自动检测并更新driver文件,提高selenium代码的稳定性

Project description

介绍

浏览器的更新和driver文件的版本异常,经常是影响代码稳定性的一个原因,而每次driver文件的更新也是比较繁杂的工作,此次的safe-driver意在帮助维护driver的稳定性

作用

safe-driver导入后,可替换selenium的webdriver,使用方式和方法同selenium的webdriver 当启动浏览器driver文件出错时,程序将自动下载并更新浏览器驱动,并重新返回driver,提高代码的稳定性

导入

from SafeDriver.drivers import driver
from SafeDriver.drivers import option

使用

此操作同selenium的webdriver.Chrome()

driver = driver()
driver.get("https://www.baidu.com")

放入options参数

首先确定导入option配置参数 使用同selenium的ChromeOptions,可直接添加,添加后,无需再次写入到driver中

from SafeDriver.drivers import option
option.add_argument('--headless')

路径和系统配置

路径和系统保存在option中,配置需要导入option

from SafeDriver.drivers import option
option.pypath = 'xxx' # python的根目录路径
option.os_ = 'xxx'  # 当前使用的操作系统

注意事项:

1、option.os_:参数不赋值,则视为自动查找当前操作系统 2、option.pypath:参数不赋值,则视为自动查到python路径(目前自动查找操作系统仅支持windows系统,linux和mac用户请手动配置option.pypath属性)

目前仅支持chrome浏览器,暂未更新其他浏览器

使用问题快查

在mac和linux上,SafeDriver不好使

SafeDriver自动查找的路径是python的路径,这个查找,在linux和mac上面并不一定能正常进行,linux和mac的用户,最好是手动配置好option.os_和option.pypath

如果更好保持稳定性?

建议代码中,指定driver的保存路径,此时的option.pypath则需要是你保存driver的路径

mac用户不能移动文件

这属于mac系统的限制,某些路径需要进行授权才能访问和显示,所以可以将driver文件放在可直接访问的目录,在代码中设置好driver路径,并将这个路径赋值给option.pypath

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

SafeDriver-1.2.9.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

SafeDriver-1.2.9-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file SafeDriver-1.2.9.tar.gz.

File metadata

  • Download URL: SafeDriver-1.2.9.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for SafeDriver-1.2.9.tar.gz
Algorithm Hash digest
SHA256 5958c334a4e0407903b41bf3c58a2f87fa1c1fb275ee41931ede15b767e3e6fb
MD5 97ef6d5c61f60dda18878e11b4d6051c
BLAKE2b-256 1b48c466778ca9d4d51bc5d46a55d2effc1150023ac4daba386e9c69b49ef229

See more details on using hashes here.

File details

Details for the file SafeDriver-1.2.9-py3-none-any.whl.

File metadata

  • Download URL: SafeDriver-1.2.9-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.10

File hashes

Hashes for SafeDriver-1.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 253182a6a28aa9b1109f4fb88379fbb608bb7485a59304dc84cb51e8af34a2fe
MD5 bbf52422809c84cee29567a77dc73fa6
BLAKE2b-256 06f532b7b37b525353406542282ee0e1892d251ec8efc7cfd1eb79eb1400790b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page