- 论坛徽章:
- 5
|
搞了个表单登录的代码(python3.0)
这是登录地址
http://www.itxtbook.com/login.php
这是代码
不知道如何判断是否登录成功
# -*- coding:utf-8 -*-
from urllib import request,parse
class Makesocket:
def __init__(self,loginurl,param):
# login url to recieve param , Post/Get param
self.loginurl = loginurl
self.param = param
def cookie(self):
self.cookies = request.HTTPCookieProcessor()
"""opener will be used to open Url with cookie."""
"""build the cookie container."""
self.opener = request.build_opener(self.cookies)
request.install_opener(self.opener)
def run(self):
# serialize the Param
# Login to Get Cookie ,Which will be Push into self.opener.
# get request with Cookie.
self.encodeparam = parse.urlencode(self.param)
request.urlopen(self.loginurl,self.encodeparam)
conn = self.opener.open("http://www.itxtbook.com/login.php")
print (conn)
if __name__ == '__main__':
loginurl = "http://www.itxtbook.com/login.php"
param = {
'lgt':'0',
'pwuser':'shengkou',
'pwpwd':'19771228',
'hideid':'1',
'cktime':'2592000',
'submit':'login'
}
conn = Makesocket(loginurl,qdurl,param,param2)
conn.cookie()
conn.run() |
|
|