gpt4 book ai didi

selenium - 水貂 + PhantomJS : How do I set the user agent?

转载 作者:行者123 更新时间:2023-12-01 15:19:29 25 4
gpt4 key购买 nike

我将 phantomjs 与 mink 一起使用:

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

但我需要伪装成最新的 chrome。我试过这个:

    /**
* @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');
}

但我得到了异常(exception):

[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 的版本并不重要,但网络应用程序必须认为它正在与最新版本的 chrome 对话。

最佳答案

Selenium does not provide this capability, as it is not something a user can do. It's recommended you use a proxy to inject additional headers to the requests generated by the browser.

https://code.google.com/p/selenium/issues/detail?id=2047#c1

遗憾的是......然而,PhantomJS 确实提供了一个 interface for setting the headers .最好的办法是使用它的 REST API 向它发送直接命令。还有一个很酷的 PHP wrap library这将使它变得容易 200 倍。

关于selenium - 水貂 + PhantomJS : How do I set the user agent?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25319882/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com