webdriver 呼叫瀏覽器失敗

來源:互聯網
上載者:User

標籤: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 呼叫瀏覽器失敗

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.