2014-12-22 49 views
5

我怎麼都找不到下手的命令行選項phantomjs像--cookies-file=/path/to/cookies.txt等...如何在Selenium中使用命令行選項啓動PhantomJS?

嘗試driver = webdriver.PhantomJS('--cookies-file=/tmp/ph_cook.txt'),但沒有。

未知原因add_cookie不工作以保持記錄。

我試圖啓動phantomjs這樣的:

driver = webdriver.PhantomJS(executable_path = "phantomjs --cookies-file=/tmp/ph_cook.txt --webdriver") 

,但得到的錯誤:

raise WebDriverException("Unable to start phantomjs with ghostdriver.", e) 
selenium.common.exceptions.WebDriverException: Message: Unable to start phantomjs with ghost driver. 
+0

這是http://stackoverflow.com/q/17788223/3124333的副本嗎? – SiKing

+0

@SiKing錯誤的語言,但我還沒有找到重複的。儘管如此。 –

+0

@ArtjomB。這都是硒,語言綁定應該不重要? – SiKing

回答

7

您可以將它們作爲一個列表中通過命令行參數的幕後PhantomJS實例service_args參數:

webdriver.PhantomJS(service_args=['--cookies-file=/tmp/ph_cook.txt']) 

如果驅動程序無法啓動, n語言綁定可能無法正確確定PhantomJS可執行文件的位置。您可能需要另外將完整路徑傳遞給參數executable_path。請注意,如果您通過npm安裝PhantomJS,則實際的可執行文件不會直接位於全局包目錄中,而是直接位於其子文件夾中。

+0

使用webdriver.Remote時有什麼辦法可以做到這一點嗎?換句話說,如果我在seleniumhub上運行phantomJS,我可以將它傳遞給代理嗎? webdriver.Remote不會將service_args作爲參數 – izyda