標籤:ati google can service 科學上網 his 成功 print self
用webdriver呼叫瀏覽器的時候發生了錯誤
提示:
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver
大致意思是連結不到服務,找不到路徑
解決方案:
一、用百度查了一下,並沒有發現類似的問題,後面用google有查到一樣的問題,但很遺憾並沒有人給出解答
二、嘗試從PATH下手,發現一切正常
這時候已經開始有點慌了
三、查看hosts檔案配置
cat /etc/hosts
# This work is licensed under a CC BY-NC-SA 4.0 International License.
# https://creativecommons.org/licenses/by-nc-sa/4.0/
# Localhost (DO NOT REMOVE)
127.0.0.1TKPT450
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
嘗試添加127.0.0.1 localhost
再運行代碼
#!/usr/bin/env python
# -*- coding:UTF-8 -*-
from selenium import webdriver
firefox_driver = webdriver.Firefox()
firefox_driver.get("http://www.baidu.com")
print firefox_driver.title
firefox_driver.quit()
OK,調用成功。
百度一下,你就知道
[Finished in 5.3s]
總結,之前有修改過hosts以方便科學上網,把127.0.0.1 localhost刪掉了,但事實上然並卵。
webdriver 呼叫瀏覽器失敗