二、自动登录源代码(来源于网络)
_login_url = 'http://home.51cto.com/index.php?s=/Index/doLogin'
_method = 'post'
#email 51cto登录用户名或邮箱
#passwd 51cto登录密码
_login_data = {
'email':'***@qq.com',\
'passwd':'***',\
}
_headers = [
('host','home.51cto.com'),\
('User-Agent','Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2'),\
('Referer','http://home.51cto.com/index.php?s=/Index/index/reback/http%253A%252F%252Fwww.51cto.com%252F/')\
]
_data = {
'cookie_file_path':'./51cto_cookies.dat'
}
_re = r'src="(.+?)"'
_version = '0.1'
_connect_info = {}
def __init__(self):
self._connect_info['cookie'] = cookielib.LWPCookieJar()
try:
self._connect_info['cookie'].revert(self._data['cookie_file_path'])
except Exception,e:
print e
self._connect_info['cookie_processor'] = urllib2.HTTPCookieProcessor(self._connect_info['cookie'])
self._connect_info['post_data'] = urllib.urlencode(self._login_data)
def open(self):
opener = urllib2.build_opener(self._connect_info['cookie_processor'])
opener.addheaders = self._headers
urllib2.install_opener(opener)
#opener.open(request)
request = urllib2.Request(self._login_url,self._connect_info['post_data'])
conn = opener.open(request)
if(conn.geturl() == self._login_url):
self._connect_info['cookie'].save(self._data['cookie_file_path'])
else:
pass
#根据js中的链接连接登录
partner = re.compile(self._re)
match = partner.findall(conn.read())
for item in match:
opener.open(item)
#登录成功开始领豆
url = 'http://down.51cto.com/download.php'
data = {'do':'getfreecredits','t':random.random()}
opener.open(url, urllib.urlencode(data))
#html = opener.open('http://down.51cto.com/')
#领无忧币
url = 'http://home.51cto.com/index.php?s=/Home/toSign'
data = {'s':''}
opener.open(url, urllib.urlencode(data))
if __name__ == '__main__':
login_51cto = Login()
login_51cto.open()
自行把账号密码换成自己的,另存为“51CTO.py”(名字没影响)
三、VBS实现自动化
如果你能接受DOS黑框框的话可以直接上批处理
这里上个最简单的VBS执行批处理
1.创建批处理
wscript.sleep 10000>C:\Sleep.Vbs :延迟设置10秒
闪讯.lnk :和批处理放一起就写相对路径了
start /wait C:\Sleep.Vbs :延迟
51CTO.lnk :和批处理放一起就写相对路径了
迅雷树.lnk :和批处理放一起就写相对路径了
2.VBS隐藏黑框运行
dim wsh
set wsh=createobject("wscript.shell")
wsh.run "启动.bat",vbhide '和批处理放一起就写相对路径了
现在只要运行这个VBS就能自动领豆了