chromedriver使用硒刮

时间:2019-02-18 13:26:20

标签: python python-3.x selenium selenium-webdriver web-scraping

我正在尝试在命令中使用selenium加载chrome web驱动程序,但出现错误

1)我已将Chrome浏览器和网络驱动程序更新为最新版本 2)通过使用相同版本的chrome浏览器和驱动程序进行检查

from selenium import webdriver
driver=webdriver.Chrome('C:/Users/prasun.j/Desktop/chromedriver')

我希望弹出一个浏览器窗口,但出现此错误

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\prasun.j\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "C:\Users\prasun.j\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "C:\Users\prasun.j\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\Users\prasun.j\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "C:\Users\prasun.j\AppData\Local\Continuum\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to write automation extension zip
  (Driver info: chromedriver=73.0.3683.20 (8e2b610813e167eee3619ac4ce6e42e3ec622017),platform=Windows NT 10.0.14393 x86_64)

1 个答案:

答案 0 :(得分:3)

  
      
  • 确保您已经安装了硒包
  •   
  • here(最新版本-73+)下载chromedriver.exe,并将其插入代码中(请确保已解压缩)。
  •   
  • 还将“ /”替换为“ \\”。
  •   
  • 安装适当的Chrome驱动程序(73+),以便与chromedriver版本(也适用于73 +)
  •   
  • 检查下面的答案...
  •   

从CHROMEDRIVER官方网站上注意这一点:

enter image description here

正确用法:

driver=webdriver.Chrome('C:\\User\\prasun.j\\Desktop\\chromedriver.exe')

# or as @MosheSlavin answered 

driver=webdriver.Chrome(r'C:\Users\prasun.j\Desktop\chromedriver.exe')

希望我能帮助您!