我正在尝试使用watir-webdriver访问一个站点.该网站根据"Accept-Language"请求标头将所有内容翻译成另一种语言,结果使用错误的语言.
我正在尝试设置自定义标头,phantomjs接受(http://phantomjs.org/api/webpage/property/custom-headers.html),如下所示:
require 'watir-webdriver' capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs( "phantomjs.page.settings.userAgent" => "Mozilla/5.0", "phantomjs.page.customHeaders" => {'Accept-Language' => 'en-GB,en-US;q=0.8,en;q=0.6' } ) b = Watir::Browser.new :phantomjs, :desired_capabilities => capabilities
测试一下:
b.goto 'http://pgl.yoyo.org/http/browser-headers.php' File.open("/tmp/headers.html", "w") { |io| io.write b.html }
Accept-Language
结果/tmp/headers.html
中显示的标题与我指定的标题不匹配.我试图把它写成一个json字符串,但仍然没有去.