python Basic Authentication
来源:互联网 发布:foxmail mac邮件位置 编辑:程序博客网 时间:2024/05/18 03:30
有时候我们需要python解析一些页面,实现自动化监控的功能。而这些页面一般需要用户输入username,password进行基本的验证,这时就需要我们使用python基本的认证功能。现已python抓取dubbo-admin的服务页面进行举例:
# create a password managerpassword_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()# Add the username and password.top_level_url = "http://1000.906.400.1620:88889/dubbo-admin/governance/services"username = "root"password = "testroot"password_mgr.add_password(None, top_level_url, username, password)handler = urllib2.HTTPBasicAuthHandler(password_mgr)# create "opener" (OpenerDirector instance)opener = urllib2.build_opener(handler)# use the opener to fetch a urlopener.open(top_level_url)# Install the openerurllib2.install_opener(opener)# Now all calls to use urllib2.urlopen use our opener.print urllib2.urlopen(top_level_url).read()
说明:这种认证解决了访问一个网页需要输入用户名、密码的认证,却没有专门的login请求的页面的认证方式。(不像qzone, 人人等都有一个类似login.do的post请求)。
0 0
- python Basic Authentication
- Python 请求 REST API 及 Basic Authentication 登录认证
- Implement basic HTTP authentication
- HTTP: Basic Authentication
- HTTP Basic Authentication认证
- Basic access authentication
- Spring Security Basic Authentication
- urllib2: Basic Authentication
- Tomcat Basic Authentication
- newlisp HTTP Basic Authentication
- HTTP: Basic Authentication
- HTTP Basic Authentication
- Tomcat配置Basic Authentication
- HttpClient Basic Authentication
- HTTP Basic Authentication认证
- Basic access authentication
- HTTP Basic Authentication
- Tomcat WebSocket basic authentication
- Spring中bean的作用域
- Spark学习笔记1-Scala基础语法
- Objective-C语言——委托模式(代理模式)
- 自定义组件点击只有down事件,原理深度解析
- undefined reference to 'WinMain@16'
- python Basic Authentication
- CALayer - 12
- iOS 常量的声明和实现
- Android菜单
- mysql的binlog太大
- Installing Jenkins on Red Hat distributions
- 【C++】STL--QUEUE
- HDU 1016 Prime Ring Problem(DFS)
- 《剑指offer》——反转链表