初识User Agent
上一篇 /
下一篇 2014-01-15 16:10:16
/ 个人分类:Selenium
User Agent(UA)是HTTP协议中的一部分,它向访问网站提供你所使用的浏览器类型、
操作系统及版本、CPU类型、浏览器渲染引擎、浏览器语言、浏览器插件等信息的标识。UA字符串在每次浏览器HTTP请求时都发送到服务器。
要知道当前使用浏览器的UA,在地址栏中输入:javascript.:alert(navigator.userAgent)
针对FireFox浏览器来说,有个插件叫User agent switcher,可以在不同UA之间切换,把自己伪装成其他浏览器。举例来说,点击工具中将Default User Agent改成iPhone3.0,这样就能伪装成iPhone3.0的
手机浏览打开网页了,打开
http://wap.sina.com试试看吧。
在FireFox的地址栏中输入about:config,会显示所有的preference,如下图:
用以下方法可设置profile中的一个preference(geo.enabled为preference中的任意一个,false为所设置的value):
FirefoxProfile profile = new FirefoxProfile();
profile.SetPreference("geo.enabled", false);
FirefoxDriver ffd = new FirefoxDriver(profile);
此外,还能设置FireFox代理的功能:
Proxy p = new Proxy();
p.HttpProxy = 。。。。。。
p.FtpProxy = 。。。。。。
p.SslProxy = 。。。。。。
profile.SetProxyPreference(p);
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
收藏
举报
TAG: