新手区 [求助] mac +selenium+python 环境搭建问题

· 2016年11月30日 · 最后由 wolf5 回复于 2017年01月15日 · 1930 次阅读
  • 最近因为工作需要要用 mac 搭建 selenium 的环境,因为我之前一直都是用的 windows,因此在搭建过程中遇到了问题
  • 我将下载到的 chromedriver 随便放在一个文件夹下,并在代码中指明了 driver 的路径

代码如下

from selenium import webdriver

driver=webdriver.Chrome("/Users/lucyxu/Downloads/chromedriver")
driver.get("http://www.baidu.com")

报错代码如下:

/System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support --client 127.0.0.1 --port 51792 --file /Users/lucyxu/automation/klmwapnew/test/test.py
pydev debugger: process 1101 is connecting

Connected to pydev debugger (build 143.1559)
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2407, in <module>
    globals = debugger.run(setup['file'], None, None, is_module)
  File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1798, in run
    launch(file, globals, locals)  # execute the script
  File "/Users/lucyxu/automation/klmwapnew/test/test.py", line 3, in <module>
    driver=webdriver.Chrome("/Users/lucyxu/Downloads/chromedriver")
  File "/Library/Python/2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/Library/Python/2.7/site-packages/selenium/webdriver/common/service.py", line 76, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Exception AttributeError: "'Service' object has no attribute 'process'" in <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x10489cb50>> ignored

因为找了很久,这个问题没有得到解决,故请解决过这个问题的朋友施以援手,万分感谢

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
共收到 3 条回复 时间 点赞

随手一搜chromedriver executable may have wrong permissions

  1. Unzip the chromedriver.zip
  2. Move the file to /usr/bin directory sudo mv chromedriver /usr/bin
  3. Goto /usr/bin directory and you would need to run something like "chmod a+x chromedriver" to mark it executable.

Message: 'chromedriver' executable may have wrong permissions

权限不对

晚上刚刚解决这个问题。
mac10.12,/usr/bin/默认不能修改,root 用户也不行。可以把下载的 chromedriver 放到/usr/local/bin 目录,PATH 里/usr/local/bin 调用顺序优先于/usr/bin。楼主可以试试

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册