设为首页 加入收藏

TOP

python遇到使用selenium的问题(一)
2023-07-23 13:35:46 】 浏览:40
Tags:python selenium

最近在学着使用blackwidow这个工具,在ubuntu20.02系统的安装过程当中遇到了selenium使用的一些问题。

selenium是个什么工具? 

Selenium是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就像真正的用户在操作一样。支持的浏览器包括IE(7, 8, 9, 10, 11),Mozilla Firefox,Safari,Google Chrome,Opera,Edge等。这个工具的主要功能包括:测试与浏览器的兼容性——测试应用程序看是否能够很好得工作在不同浏览器和操作系统之上。测试系统功能——创建回归测试检验软件功能和用户需求。支持自动录制动作和自动生成.Net、Java、Perl等不同语言的测试脚本

这一个工具同时也集成到了python的库当中,通过引用模块就可以使用。

不过如果遇到了以下这种错误:

/usr/lib/python3/dist-packages/requests/__init__.py:89: RequestsDependencyWarning: urllib3 (1.26.12) or chardet (3.0.4) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
crawl.py:29: DeprecationWarning: use options instead of chrome_options
  driver = webdriver.Chrome(chrome_options = chrome_options)
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 71, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "/usr/lib/python3.8/subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/lib/python3.8/subprocess.py", line 1704, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "crawl.py", line 29, in <module>
    driver = webdriver.Chrome(chrome_options = chrome_options)
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
    super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/chromium/webdriver.py", line 89, in __init__
    self.service.start()
  File "/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

Selenium3.x调用浏览器必须有一个webdriver驱动文件,错误是no such file or directory: "chromedriver"的意思就是电脑没有安装chrome,也没有找到软件路径。需要先去官网上下载一下这个压缩包

parallels@parallels-Parallels-Virtual-Platform:~/BlackWidow$ sudo wget https://chromedriver.storage.googleapis.com/107.0.5304.18/chromedriver_linux64.zip
--2022-10-13 18:57:21--  https://chromedriver.storage.googleapis.com/107.0.5304.18/chromedriver_linux64.zip
Resolving chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)... 142.250.204.48
Connecting to chromedriver.storage.googleapis.com (chromedriver.storage.googleapis.com)|142.250.204.48|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 6876869 (6.6M) [application/zip]
Saving to: ‘chromedriver_linux64.zip’

chromedriver_linux64.zip                        100%[====================================================================================================>]   6.56M  5.34MB/s    in 1.2s    
2022-10-13 18:57:22 (5.34 MB/s) - ‘chromedriver_linux64.zip’ saved [6876869/6876869]

安装之后进行解压,然后就直接得到一个可执行文件,我们再

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇nginx访问控制,用户认证,配置ht.. 下一篇2022年安装fedora workstation 36..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目