- 论坛徽章:
- 0
|
如果用pycurl的话
怎么样写个代码自动登陆CU呢?
望高手高手指点一二
下面是我的代码
不能成功
- #!/usr/bin/env python
- # -*- coding:GB2312 -*-
- import pycurl,urllib,StringIO,sys
- CU_URL = 'http://sso.chinaunix.net/Login'
- UserName = 'mimimi'
- Password = 'lalala'
- data = {
- 'cookie_flag':'',
- 'login_name' : UserName,
- 'password' : Password,
- 'btn_login':'%B5%C7%C2%BC',
- }
- urldata = urllib.urlencode(data)
- crl = pycurl.Curl()
- fd = open('CU.html', 'w')
- crl.setopt(pycurl.WRITEFUNCTION, fd.write)
- crl.setopt(crl.POSTFIELDS, urldata)
- crl.setopt(pycurl.URL, CU_URL)
- crl.setopt(pycurl.USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)')
- crl.setopt(pycurl.COOKIEFILE, 'cookie_cu.txt')
- crl.perform()
复制代码 |
|