• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
Y-wee
博客园    首页    新随笔    联系   管理     

Linux上使用selenium报错:AttributeError: 'Service' object has no attribute 'process'

Linux上使用selenium报错:AttributeError: 'Service' object has no attribute 'process'

​ Linux 上安装了谷歌浏览器及对应版本的浏览器驱动(chromedriver),执行如下代码:

from selenium.webdriver.chrome.service import Service
from selenium import webdriver

service = Service(executable_path="/home/admin/python/py/crawler/chromedriver_win32/chromedriver")
driver = webdriver.Chrome(service=service)

​ 报错:

Traceback (most recent call last):
  File "/home/admin/python/py/crawler/test.py", line 38, in <module>
    driver = get_driver()
  File "/home/admin/python/py/crawler/test.py", line 34, in get_driver
    return webdriver.Chrome(service=service, options=options)
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    super().__init__(
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
    self.service.start()
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 106, in start
    self.assert_process_still_running()
  File "/usr/local/python3/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
    return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'

​ 解决过程:

​ 首先检查路径浏览器驱动路径是否正确,确定路径没有写错,还是报错

​ 检查浏览器和驱动版本是否对应,执行google-chrome -version命令查看浏览器版本,执行chromedriver -version查看驱动版本;我执行查看驱动版本命令的时候发生如下报错:

bash: /usr/local/bin/chromedriver: 权限不够

​ 显示权限不够,可是我当前登录用户已经设置为 root 用户了,后面百度了一下可能是文件权限的问题;cd 到 chromedriver 目录下,执行chmod 777 chromedriver命令修改文件权限,然后再执行查看驱动版本命令就没有报错了

​ 由此想到AttributeError: 'Service' object has no attribute 'process'也可能是权限问题,所以修改代码指定路径(/home/admin/python/py/crawler/chromedriver_win32/chromedriver)下驱动的权限,然后再次执行,代码正常运行

​

​

记得快乐
posted @ 2023-02-10 11:03  Y-wee  阅读(1375)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3