예제 #1
0
def publish(msg):
        #print "Thread %s Recevied %s:" % (thread.get_ident(), msg)
        data = msg
        stime = time.time()
        print stime
        print data['type'],data['time']
        
        logindata={}
        logindata = data['login']
        
        postdata = {}
        postdata = data['post']
        id = data['attr']['id']
        attr = data['attr']
        #for item in postdata:
            #print item,postdata[item]
        
        cookie = cookielib.CookieJar()
        datagen = urllib.urlencode(logindata)
        request = urllib2.Request("http://post.58.com/ajax/?action=userreglogin",datagen, headers)
        httpsHandler = urllib2.HTTPHandler()        
        httpsHandler.set_http_debuglevel(1)
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie),httpsHandler)
        
        # Actually do the request, and get the response
        result = opener.open(request).read()
        
        if result == "{result:'1', error:''}":
            #print opener.open("http://my.58.com").read()
            #postdata['fileUploadInput'] = ''
            #postdata['Pic'] = upimg(attr['img'])
            #postdata['PicDesc'] = ''
            #postdata['Content'] = '位于东环路沿线,公交路线众多!有园区多家厂车经过!还有家乐福就在对面,生活购物非常方便!房子精装修,有四个空调,其他家电家具都有!拎包入住!有意者从速!好房不等人!'
            #postdata['PicPos'] = 1
            for row in postdata:
                print row,postdata[row]
            time.sleep(0.0001)
            datapost =urllib.urlencode(postdata)
            
            request = urllib2.Request("http://post.58.com/5/8/s5/submit", datapost, headers)
            log = opener.open(request).read()
            #print log
            infoid = parsebody.rect(log, "infoid=(\d+)&")
            postpath = '/home/myapp/workspace/wwwroot/jjr/post/suzhou/'+id+'.html'            
            if infoid:
                           
                open(postpath,'w').write(str(time.time() - stime)+" 网址为:http://su.58.com/zufang/"+infoid+"x.shtml")
                print postpath
                print time.time()
                print time.time() - stime
            else:
                log = parsebody.rect(log, "'(.*?)'") if parsebody.rect(log, "'(.*?)'") else ''
                log1 = parsebody.rect(log, "'msg':\[(.*?)\]") if parsebody.rect(log, "'msg':\[(.*?)\]") else ''
                open(postpath,'w').write(log+log1)
                print postpath
                print time.time()
                print time.time() - stime
예제 #2
0
def upimg(img):
    register_openers()
    datagen, headers1 = multipart_encode({"fileUploadInput": open(img,"rb"),
                                       "backFunction": "$.c.Uploader.finish"})
    for k in headers1:
        headers[k] =headers1[k]
    request = urllib2.Request("http://post.58.com/upPicWeb2.aspx", datagen, headers)
    r = urllib2.urlopen(request).read()
    if r :
        return parsebody.rect(r, " '(.*?)',")
    else:
        return False