【问题标题】:Watir PhantomJS driver optional argument for ignoring SSL errors?忽略 SSL 错误的 Watir PhantomJS 驱动程序可选参数?
【发布时间】:2013-12-05 17:21:31
【问题描述】:

大家好,

我正在致力于自动化一些 Ruby 脚本以使其无头。我最初的做法 是尝试 Watir 及其 PhantomJS 模块。我们的本地测试环境使用自签名 我知道某些浏览器会出错的证书。我知道 PhantomJS 有一个 ignoreSSLerrors 选项,但不知道如何指定 PhantomJS 驱动程序应该使用 它。我可以毫无问题地创建一个无头浏览器 phantom-js 会话,但是当我尝试时 使用自签名证书导航到网页,我什么也没得到 - 没有错误,没有 文本,没有说明为什么我的页面没有加载。

基本上,这就是发生的事情(odysseyURL 在其他地方被定义为字符串 URL, Firefox 可以毫无问题地加载):

irb(main):035:0* driver = Watir::Browser.new :phantomjs
PhantomJS is launching GhostDriver...
[INFO  - 2013-12-05T15:48:49.998Z] GhostDriver - Main - running on port 8910
[INFO  - 2013-12-05T15:48:50.219Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
 -_decorateNewWindow - page.settings{"XSSAuditingEnabled":false,
"javascriptCanCloseWindows":true,"javascriptCanOpenWindows":true,"
javascriptEnabled":true,"loadImages":true,"localToRemoteUrlAccessEnabled":false,
"userAgent":"Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/534.34 (KHTML, like 
Gecko) PhantomJS/1.9.2 Safari/534.34","webSecurityEnabled":true}
[INFO  - 2013-12-05T15:48:50.252Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
- page.customHeaders:  - {}
[INFO  - 2013-12-05T15:48:50.262Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
- CONSTRUCTOR - Desired Capabilities:{"browserName":"phantomjs","version":"",
"platform":"ANY","javascriptEnabled":true,"cssSelectorsEnabled":true,
"takesScreenshot":true,"nativeEvents":false,"rotatable":false}
[INFO  - 2013-12-05T15:48:50.283Z] Session [bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15]
- CONSTRUCTOR - Negotiated Capabilities: {"browserName":"phantomjs","version":
"1.9.2","driverName":"ghostdriver","driverVersion":"1.0.4","platform":
"windows-8-32bit","javascriptEnabled":true,"takesScreenshot":true,"handlesAlerts":
false,"databaseEnabled":false,"locationContextEnabled":false,
"applicationCacheEnabled":false,"browserConnectionEnabled":false,
"cssSelectorsEnabled":true,"webStorageEnabled":false,"rotatable":false,
"acceptSslCerts":false,"nativeEvents":true,"proxy":{"proxyType":"direct"}}
[INFO  - 2013-12-05T15:48:50.327Z] SessionManagerReqHand -
_postNewSessionCommand - New Session Created: bc1bd280-5dc4-11e3-8b99-7bac3d2f1d15
=> #<Watir::Browser:0x73fac05c url="about:blank" title="">
irb(main):036:0>
irb(main):037:0* =begin
<en processed and works headless.  Everything below is still being modified
irb(main):039:0= =end
irb(main):040:0*
irb(main):041:0* driver.goto(odysseyURL)
=> "about:blank"
irb(main):042:0> puts(driver.text)

=> nil
irb(main):043:0> puts(driver.html)
<html><head></head><body></body></html>
=> nil

我已经搜索和研究了 Watir 和 Ghostdriver 以获取有关此类任何内容的文档,但发现的很少,也没有任何东西可以帮助我。

任何帮助将不胜感激, mpozos

【问题讨论】:

    标签: watir phantomjs self-signed headless ghostdriver


    【解决方案1】:

    我通过在 https 页面上启动 watir / phantomjs 遇到了同样的问题,结果相同

    <html><head></head><body></body></html>
    

    所以我尝试使用 mechanize 绕过它,但我遇到了另一个问题..

    这是由于 ssl 证书。我解决它添加 ssl 版本和 '不考虑 ssl 错误' 在新实例中..但我仍然需要解决主要的 watir 问题..

    我找到了以下信息,我将在今晚进行测试..

    第一个,在启动 phantomjs 时包含更多信息:

    switches = ['--proxy=69.106.88.7:60199', '--proxy-auth=username:password123']
    browser = Watir::Browser.new :phantomjs, :args => switches
    

    二、phantomjs的用法:

    Usage: phantomjs [options] script.[js|coffee] [script argument [script argument ...]]
    Options:
        --load-images=[yes|no]             Load all inlined images (default is 'yes').
        --load-plugins=[yes|no]            Load all plugins (i.e. 'Flash', 'Silverlight', ...)  (default is 'no').
        --proxy=address:port               Set the network proxy.
        --disk-cache=[yes|no]              Enable disk cache (at desktop services cache storage location, default is 'no').
        --ignore-ssl-errors=[yes|no]       Ignore SSL errors (i.e. expired or self-signed certificate errors).
    

    所以我想测试一下这个解决方案:

    switches = ['--ignore-ssl-errors=yes']
    browser = Watir::Browser.new :phantomjs, :args => switches
    

    然后我会公布结果

    编辑:这个解决方案我没有成功..我直接去无头的..希望这有帮助

    【讨论】:

    • 谢谢你,browser = Watir::Browser.new :phantomjs, :args =&gt; ['--ignore-ssl-errors=yes'] 真的有帮助!
    • 不得不将它与较新的 Phantomjs 一起使用,它不会导航到 https 站点(甚至 google.com)而不告诉它忽略 ssl 错误..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-31
    • 1970-01-01
    • 1970-01-01
    • 2012-05-10
    • 2014-07-30
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多