Created
June 15, 2011 04:27
-
-
Save anonymous/1026484 to your computer and use it in GitHub Desktop.
cnzz login
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding:utf-8 | |
import urllib | |
import urllib2 | |
import cookielib | |
class CnzzClient(): | |
def __init__(self, username, password): | |
self.username = username | |
self.password = password | |
self.cj = cookielib.CookieJar() | |
self.opener = urllib2.build_opener( | |
urllib2.HTTPCookieProcessor(self.cj), | |
) | |
self.headers = { | |
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0.1) Gecko/20100101 Firefox/4.0.1', | |
'Accept-Language':'en-US', | |
} | |
def req(self,url,params=None, headers=None): | |
headers = headers or self.headers | |
if params is None: | |
request = urllib2.Request(url,headers=headers) | |
elif isinstance(params,(tuple, dict)): | |
request = urllib2.Request(url,urllib.urlencode(params),headers=headers) | |
else: | |
request = urllib2.Request(url,params,headers=headers) | |
return self.opener.open(request).read() | |
def login(self): | |
''' | |
登陆,返回 | |
''' | |
params = { | |
'username':self.username, | |
'password':self.password, | |
'list':1, | |
} | |
ret = self.req('http://new.cnzz.com/user/login.php', params) | |
#判断是否登陆成功,你自己完成吧。我没测试账号。 | |
return True | |
if __name__ == '__main__': | |
cc = CnzzClient('username', 'password') | |
print cc.login() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment