【问题标题】:How to start PhantomJS with commandline options in Selenium?如何在 Selenium 中使用命令行选项启动 PhantomJS?
【发布时间】:2014-12-22 22:29:04
【问题描述】:

我找不到如何使用 --cookies-file=/path/to/cookies.txt 等命令行选项启动 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.

【问题讨论】:

  • @SiKing 语言错误,但我还没有找到重复的。不过一定有。
  • @ArtjomB。都是 Selenium,语言绑定不重要?

标签: python selenium cookies webdriver phantomjs


【解决方案1】:

您可以通过将命令行参数作为列表传递给service_args 参数,将命令行参数传递给幕后的 PhantomJS 实例:

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

如果驱动程序无法启动,则语言绑定可能无法正确确定 PhantomJS 可执行文件的位置。您可能还需要将完整路径传递给 executable_path 参数。注意,如果你通过 npm 安装 PhantomJS,实际的可执行文件不是直接在全局包目录中,而是在它的子文件夹中。

【讨论】:

  • 在使用 webdriver.Remote 时有什么办法吗?换句话说,如果我在 seleniumhub 上运行 phantomJS,我可以将它传递给代理吗? webdriver.Remote 不以 service_args 作为参数
猜你喜欢
  • 1970-01-01
  • 2020-05-17
  • 2015-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-26
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多