鱼C论坛

 找回密码
 立即注册
查看: 865|回复: 3

关于selenium

[复制链接]
发表于 2018-8-3 22:25:16 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 蛊惑的心 于 2018-8-3 23:52 编辑

今天刚刚装selenium,看网上的教程运行了一段代码
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('http://www.baidu.com/')
然后chrome打开了,但是百度网页却没有打开,而且一段时间后自动退出chrome且报错
报错如下:
Traceback (most recent call last):
  File "C:/Users/头条杀机/AppData/Local/Programs/Python/Python37/aa.py", line 3, in <module>
    browser = webdriver.Chrome()
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 75, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 156, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 251, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
    self.error_handler.check_response(response)
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: session not created exception: Chrome version must be >= 67.0.3396.0
  (Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.3.9600 x86_64)

我的chrome版本是68.0.3440.84
chrome驱动版本是2.4(它写着支持67-69),环境变量我设置在另一个盘符下了,和chrome.exe不在一个文件夹(不知道是否有影响)
所以为什么会出现这样的错误呢,为什么和教程结果不一样呢。。

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2018-8-3 22:34:14 | 显示全部楼层
我将chrome驱动和chrome.exe放在一个文件夹下了,而且改了环境变量,这一次直接报错,打都打不开,之所以换是因为我觉得之前打开的是cent的chrome.exe
报错如下:
Traceback (most recent call last):
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 756, in __init__
    restore_signals, start_new_session)
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\subprocess.py", line 1155, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] 系统找不到指定的文件。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/头条杀机/AppData/Local/Programs/Python/Python37/aa.py", line 2, in <module>
    browser = webdriver.Chrome()
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
    self.service.start()
  File "C:\Users\头条杀机\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2018-8-3 22:38:37 | 显示全部楼层
试试将chromedriver放在python目录里(与python.exe文件同一目录)
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-8-3 22:44:39 | 显示全部楼层
Tom.Error 发表于 2018-8-3 22:38
试试将chromedriver放在python目录里(与python.exe文件同一目录)

谢谢,我已经找到解决方法了
具体为:https://blog.csdn.net/lvsehaiyang1993/article/details/80599604
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 02:28

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表