爬虫--登录网页
#!/usr/bin/env python # -*- coding: utf-8 -*- ############################################# # File : loginMMVOIP.py # Author : lucasysfeng # Revision : 2014-06-13 14:26:11 # Description : 登录-->获取cookie-->访问任意URL ############################################# import cookielib import urllib2 import urllib ### loginURL和postVales通过填写表单页面源码或Fiddler等抓包软件获得 ### loginURL是处理登录请求的页面(不是填写表单的页面), loginURL = "" postValues = {} ### 存储cookie cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) ### 登录验证 try: opener.open(loginURL, urllib.urlencode(postValues)) except: print "error: open() error" # 登录后可访问任意URL print opener.open("").read()