我找不到如何使用命令行选项启动 phantomjs,例如 --cookies-file=/path/to/cookies.txt
和其他...
尝试了 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.
最佳答案
您可以将命令行参数作为列表传递给 service_args
参数,从而在幕后将命令行参数传递给 PhantomJS 实例:
webdriver.PhantomJS(service_args=['--cookies-file=/tmp/ph_cook.txt'])
如果驱动程序无法启动,则语言绑定(bind)可能无法正确确定 PhantomJS 可执行文件的位置。您可能还需要将完整路径传递给 executable_path
参数。请注意,如果您通过 npm 安装 PhantomJS,则实际的可执行文件并不直接位于全局包目录中,而是位于它的子文件夹中。
关于python - 如何在 Selenium 中使用命令行选项启动 PhantomJS?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27611408/