Python+Webdriver+Phantomjs,设置不同的User-Agent,获得的url不一致
2015-03-09 15:53
337 查看
话不多说,代码如下:
得到运行结果是:
u""" @author: xieyanfen1990@126.com @attention: this is PhantomJS about webdriver and settings User-Agent """ from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities url="http://m.dianping.com/forum/note/7868689" ua1=("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) ""Gecko/20100101 Firefox/25.0") dcap = dict(DesiredCapabilities.PHANTOMJS) dcap["phantomjs.page.settings.userAgent"] = ua1 driver=webdriver.PhantomJS(desired_capabilities=dcap) driver.get(url) current_url=driver.current_url print "the first url is :"+current_url ua2=('Mozilla/5.0 (iPhone; CPU iPhone OS 7_0 like Mac OS X; en-us) AppleWebKit/537.51.1 (KHTML, like Gecko) Version/7.0 Mobile/11A465 Safari/9537.53') dcap["phantomjs.page.settings.userAgent"] = ua2 driver=webdriver.PhantomJS(desired_capabilities=dcap) driver.get(url) current_url=driver.current_url print "the second url is :"+current_url
得到运行结果是:
CindydeMacBook-Pro:httpreader cindy$ python test.py the first url is :http://s.dianping.com/topic/7868689 the second url is :http://m.dianping.com/forum/note/7868689
相关文章推荐
- 轻松自动化---selenium-webdriver(python) (二)---打印URL,设置浏览器固定宽前进后退等
- python webdriver中对不同下拉框通过文本值的选择
- 设置 PhantomJs 的 User-Agent 的方法
- python webdriver spider via phantomjs
- ios 获得webview user-agent
- HttpUrlConnection设置User-Agent
- python 与 webdriver结合打开不同浏览器
- Selenium2(WebDriver)总结(一)---启动不同浏览器、设置profile&加载插件
- Python+Selenium,使用WebDriver启动Firefox,但不打开URL
- 20171013学习笔记Selenium 2 第四章WebDriver API 4.6获得验证消息 4.7设置元素等待
- android 设置webview的浏览器标识 User-Agent
- CTSFail解决办法 android.webkit.cts.WebSettingsTesttestUserAgentString_default 和libcore.java.net.URLfail
- gtk webkit 设置user-agent
- asp.net 4.0 在webconfig 设置 url映射
- 使用HttpWebRequest获得URL的返回值
- selenium webdriver w/python learning
- Web浏览器的HTTP_USER_AGENT [转]
- python通过URL获得的网络文件可否当做普通的文件来进行访问
- iPhone开发技巧之私有API(6)--- 设置UIWebView中的User-Agent
- (User Agent Switcher)扩展Firefox来设置和切换User-Agent(UA)