51Testing软件测试论坛

标题: 想学习一下爬虫,安装好selenium后,打开谷歌失败,请问怎么解决呢。 [打印本页]

作者: 测试积点老人    时间: 2022-2-8 10:58
标题: 想学习一下爬虫,安装好selenium后,打开谷歌失败,请问怎么解决呢。

源码:

1、导入selenium

from selenium import webdriver

2、创建浏览器操作对象

path = 'chromedriver.exe'

browser = webdriver.Chrome(path)

3、访问网站
  1. url = 'https://www.jd.com/'

  2. browser.get(url)

  3. 错误:
  4. F:\pycharm_stu\crawler_learning\078_爬虫_selenium_基本使用.py:9: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  5. browser = webdriver.Chrome(path)
  6. Traceback (most recent call last):
  7. File "D:\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 71, in start
  8. self.process = subprocess.Popen(cmd, env=self.env,
  9. File "D:\Python310\lib\subprocess.py", line 966, ininit
  10. self._execute_child(args, executable, preexec_fn, close_fds,
  11. File "D:\Python310\lib\subprocess.py", line 1435, in _execute_child
  12. hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
  13. FileNotFoundError: [WinError 2] 系统找不到指定的文件。

  14. During handling of the above exception, another exception occurred:

  15. Traceback (most recent call last):
  16. File "F:\pycharm_stu\crawler_learning\078_爬虫_selenium_基本使用.py", line 9, in
  17. browser = webdriver.Chrome(path)
  18. File "D:\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, ininit
  19. super(WebDriver, self).init(DesiredCapabilities.CHROME['browserName'], "goog",
  20. File "D:\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, ininit
  21. self.service.start()
  22. File "D:\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
  23. raise WebDriverException(
  24. selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home

  25. Process finished with exit code 1
复制代码





作者: 海海豚    时间: 2022-2-9 09:31
webdriver位置放得对吗
作者: jingzizx    时间: 2022-2-9 17:53
配置的不对吧




欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) Powered by Discuz! X3.2