Mink + PhantomJS:如何设置用户代理? [英] Mink + PhantomJS: How do I set the user agent?

查看:141
本文介绍了Mink + PhantomJS:如何设置用户代理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将phantomjs与水貂一起使用:

I am using phantomjs with mink:

default:
  extensions:
    Behat\MinkExtension\Extension:
      goutte: ~
      selenium2:
        browser: phantomjs
        wd_host: http://localhost:8643/wd/hub
        capabilities:
           webStorageEnabled: true

但是我需要冒充最新的铬.我已经尝试过了:

But I need to masquerade as the latest chrome. I have tried this:

    /**
     * @BeforeStep
     */
    public function masqueradeAsLatestChrome(StepEvent $event)
    {
        $this->getSession()->setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36');
    }

但我得到了例外:

[Behat\Mink\Exception\UnsupportedDriverActionException]                                                
Exception has been thrown in "beforeStep" hook, defined in FeatureContext::masqueradeAsLatestChrome()  
Request header is not supported by Behat\Mink\Driver\Selenium2Driver

chrome的版本并不重要,但Web应用程序必须认为它与chrome的最新版本有关.

The version of chrome isn't critical but the web application must think its talking to a very recent version of chrome.

推荐答案

您应该使用Juan FranciscoCalderónZumba制造的新Behat/Mink驱动程序 https://github.com/jcalderonzumba

You should use the new Behat/Mink driver made by Juan Francisco Calderón Zumba https://github.com/jcalderonzumba

这里是直接链接到驱动程序 https://github.com/jcalderonzumba/MinkPhantomJSDriver

Here is a direct link to the driver https://github.com/jcalderonzumba/MinkPhantomJSDriver

此驱动程序允许您指定所需的请求标头 (它与Behat 3.0兼容,但我认为它至少需要PHP 5.4)

This driver allows you to specify the request headers that you need (It works with Behat 3.0 but I think it requires at least PHP 5.4)

这篇关于Mink + PhantomJS:如何设置用户代理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆