2016-12-17 108 views
0

我在cron上每小時執行一次linux服務器上都有一個chrome selenium驅動程序。我發生的錯誤只發生在隨後的運行中,也就是說,在第一次運行期間它工作正常,但在第二次或任何其他次順序運行期間,它會失敗。Selenium WebDriverException - 無法訪問chrome

raise exception_class(message, screen, stacktrace) 
selenium.common.exceptions.WebDriverException: Message: chrome not reachable 
    (Session info: chrome=54.0.2840.71) 
    (Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 4.4.0-38-generic x86_64) 

我運行這樣說:

def create_ch_driver(): 
    chrome_options = webdriver.ChromeOptions() 
    chrome_options.add_argument("--no-sandbox") 
    chrome_options.add_argument("--user-agent={}".format(config.USER_AGENT)) 
    return webdriver.Chrome("/usr/local/bin/chromedriver", chrome_options=chrome_options) 

回答

2

也許司機在後臺塊仍在運行一個新的webdriver實例的創建。

檢查進程是否在第一次執行代碼後運行。

如果是這樣嘗試殺死進程與退出():

webdriver.quit() 
+0

我使用driver.close()在我的劇本 – Saurabh

+0

每次你檢查進程是否仍在運行? –