首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >安装Chrome驱动程序,AttributeError:'Service‘对象没有属性'process’

安装Chrome驱动程序,AttributeError:'Service‘对象没有属性'process’
EN

Stack Overflow用户
提问于 2022-12-01 14:05:54
回答 1查看 33关注 0票数 0

#这是我尝试使用铬驱动程序的代码

代码语言:javascript
运行
复制
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys


driver=webdriver.Chrome(r"/usr/local/bin/chromedriver")

#但错误即将到来..

代码语言:javascript
运行
复制
<ipython-input-118-b695456c07d9>:6: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver=webdriver.Chrome(r"/usr/local/bin/chromedriver")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-118-b695456c07d9> in <module>
      4 
      5 
----> 6 driver=webdriver.Chrome(r"/usr/local/bin/chromedriver")

3 frames
/usr/local/lib/python3.8/dist-packages/selenium/webdriver/common/service.py in assert_process_still_running(self)
    114     def assert_process_still_running(self) -> None:
    115         """Check if the underlying process is still running."""
--> 116         return_code = self.process.poll()
    117         if return_code:
    118             raise WebDriverException(f"Service {self.path} unexpectedly exited. Status code was: {return_code}")

AttributeError: 'Service' object has no attribute 'process'

我检查了Chrome和Chrome驱动程序的版本和路径。但我解决不了。我是一个真正的初学者,对Python不太了解,但是,我必须爬一些数据,但我甚至不能安装一个铬驱动程序。请帮帮我,Python大师

EN

回答 1

Stack Overflow用户

发布于 2022-12-01 14:42:25

在最新的Selenium版本中,executable_path已被废弃,因此您必须使用Service

代码语言:javascript
运行
复制
from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service(<chromedriver.exe path>))
driver.get(<URL>)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74643146

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档