#coding:utf-8
import urllib,urllib2
import io,re
import cookielib
import Tkinter
from PIL import Image,ImageTk
class ytmpost:
cookiejar = cookielib.CookieJar()
handler = urllib2.HTTPCookieProcessor(cookiejar)
opener = urllib2.build_opener(handler)
response = opener.open("http://www.skxox.com/login.ashx").read()
rand = "".join(re.findall("RRIMG=\'(.*)\';", response))
def __init__(self):
self.url="http://www.skxox.com/login.ashx"
def getimage(self):
imageurl="http://www.skxox.com/rand.ashx?head=login&key=" +self.rand
image_bytes = self.opener.open(imageurl).read()
data_stream = io.BytesIO(image_bytes)
pil_image = Image.open(data_stream)
tk_image = ImageTk.PhotoImage(pil_image)
return tk_image
def postui(self):
request=self.opener.open("http://ytmsr1.skxox.com/manage/write4.ashx")
print request.read()
def loginui(self):
ytm = Tkinter.Tk()
ytm.title("login")
ytm.geometry("300x300")
l1 = Tkinter.Label(ytm, text="用户名")
l1.pack()
user_text = Tkinter.Entry()
user_text.insert(1,"ytmsr1")
user_text.pack()
l2 = Tkinter.Label(ytm, text="密码")
l2.pack()
password_text = Tkinter.Entry(show='*')
password_text.insert(1,"a123456")
password_text.pack()
tk_image=ytmpost.getimage()
Tkinter.Label(ytm, image=tk_image).pack()
yzm_text=Tkinter.Entry()
yzm_text.pack()
def getuser():
user = user_text.get()
password = password_text.get()
yzm=yzm_text.get()
return user,password,yzm
def login():
a=getuser()
user=a[0]
password=a[1]
yzm=a[2]
yzm=yzm.encode("utf-8")
print type(yzm)
values={
"ex" :"check",
"name":user,
"pass":password,
"rand":yzm+"0.2425289093078123",
}
data=urllib.urlencode(values)
print data
request=self.opener.open(self.url,data)
request=request.read()
print request
ok=re.findall('ok',request)
if len(ok)>0:
self.postui()
Tkinter.Button(ytm, text="go", command=login).pack()
ytm.mainloop()
ytmpost=ytmpost()
ytmpost.loginui()
python带cookie访问
最新推荐文章于 2024-01-13 17:53:38 发布