求个python模拟登录代码

2011-06-15 02:55:44 +08:00
 Alpha
以下是我的尝试,没有完成,谁能帮帮忙?
#!/usr/bin/python
# -*- coding: utf8 -*-
import re
import urllib
import urllib2
import cookielib

class Cnzz:
def __init__(self):
self.UserName=''
self.Password=''
self.cookie=cookielib.CookieJar()
self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cookie))
self.opener.addheaders=[('User-agent','Mozilla/5.0'),('Accept-Charset','gb2312')]
urllib2.install_opener(self.opener)

def login(self,username,password):
self.UserName=username
post_data=urllib.urlencode({'username':username,'password':password,'list':'1'})
path = 'http://www.cnzz.com/index.php'
req = urllib2.Request(url=path, data=post_data)
conn = urllib2.urlopen(req)

conn2 = urllib2.urlopen(urllib2.Request(url='http://new.cnzz.com/v1/main.php?s=site_list')).read()

return conn2

if __name__=="__main__":
cnzz=Cnzz()
y=cnzz.login('username','password')
print unicode(y,'utf-8','ignore').encode('gb2312','ignore')
5860 次点击
所在节点    Python
6 条回复
Alpha
2011-06-15 02:56:49 +08:00
补充一下,我是想登录 http://www.cnzz.com
Alpha
2011-06-15 12:12:18 +08:00
有没有朋友能指导下?
c
2011-06-15 12:16:08 +08:00
饿,没人帮你哇。吃晚饭帮你写一个吧!
c
2011-06-15 12:28:59 +08:00
https://gist.github.com/1026484

我没账号和密码,登陆的就没测试了。
Alpha
2011-06-16 00:38:24 +08:00
@c 非常感谢,这个对我很有用,谢谢。
alsotang
2011-09-10 23:02:36 +08:00
@Alpha 他那个代码用起来登录成功了没有?要修改的地方应该不会很多吧?

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/14464

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX