甚至可能吗?我目前有:
require 'selenium-webdriver'
phantomjs_useragent = {"phantomjs.page.settings.userAgent" => "Mozilla/5.0 (iPhone; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543a Safari/419.3"}
driver = Selenium::WebDriver.for :phantomjs
driver.capabilities.merge!(phantomjs_useragent)
driver.navigate.to "http://whatsmyuseragent.com/"
puts driver.first(:tag_name => 'body').text
这让我明白了,这不是我放入的用户代理:
您的用户代理:Mozilla/5.0 (Macintosh; Intel Mac OS X) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.8.1 Safari/534.34