python带cookie访问

#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()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值