#-*-coding:utf-8-*-

import cookielib, urllib, urllib2
import json

import threading,time

class Order(object):
########## login
    def __init__(self):
        print "init"

    def speak(self):
        count = 300
        url = "http://zweb.com/login"

        data='{"email":"a@test.com", "password":"***"}'
        # jdata = json.dumps(data)

        # post_data=urllib.urlencode(jdata)
        headers ={'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 8.1)','Acc
ept-Encoding': 'gzip, deflate','Connection':'keep-alive'}

        ckjar = cookielib.MozillaCookieJar('./cookie.txt2')

        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(ckjar))

        req=urllib2.Request(url,data,headers)
        req.add_header('Content-Type', 'application/json')
        result = opener.open(req)

        htm = result.read()
        print htm

        ckjar.save(ignore_discard=True, ignore_expires=True)

        url = "http://zhweb.kingsoft.com/foodBookingOrders"
        
        data = {"foodBookingPlanId":95,"items":[{"planItemId":311},{"planItemId":309},{"
planItemId":308}]}

        jdata = json.dumps(data)

        headers ={'User-Agent':'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 8.1)','Acc
ept-Encoding': 'gzip, deflate','Connection':'keep-alive'}
        while count >= 0:
            req=urllib2.Request(url,jdata)
            # req.add_header('Content-Type', 'text/plain;charset=UTF-8')
            req.add_header('Content-Type', 'application/json')
            result = opener.open(req)

            htm = result.read()
            print htm

            file_object = open('./out.txt', 'a')
            file_object.write(htm)
            file_object.close( )

            time.sleep(1)
            count=count - 1


##########
if __name__ == "__main__":
    p = Order()
    p.speak()

    #count = 1
    #while count > 0:
    #    timer = threading.Timer(5, p.speak(), (p,))
    #    print "start"
    #    timer.start()
    #    timer.join()
    #    print "after join"
    #    count=count - 1
    #    timer.cancel()

 

posted on 2017-11-24 14:12  凌度  阅读(422)  评论(0编辑  收藏  举报