def main(): global http,option http = httpCient() http.setCookieStr('isfirst=true; cookieuid1=05dvUVOk3HAxiF/EDZ3FAg==; showcountdown=true; _TCN=C4E61ED0AFABBBB66D915DE5AD94645E; operate=nofilter; id58="05dz8VOwoTdNBXV8C0QNAg=="; www58com="AutoLogin=false&UserID=26118556&UserName=selectersky&CityID=0&Email=&AllMsgTotal=0&CommentReadTotal=0&CommentUnReadTotal=0&MsgReadTotal=0&MsgUnReadTotal=0&RequireFriendReadTotal=0&RequireFriendUnReadTotal=0&SystemReadTotal=0&SystemUnReadTotal=0&UserCredit=0&UserScore=0&PurviewID=&IsAgency=false&Agencys=null&SiteKey=2A31A22D9706340595FC6E8F6DD0DB15052A0657EA27860B0&Phone=&WltUrl=&UserLoginVer=4E2D7FDC8FC545758763CE1E8F414D1CE<=1404084541614"; 58cooper="userid=26118556&username=selectersky&cooperkey=3f35337885089d3c6e0479298454d8dd"; 58passport="14040845411548924313622024&7A8AA9BF524FE0547A4BAEE92E17DCD64&f37e36"; m="98%3Aff%3Ad0%3A89%3A00%3A7a"; r="540_960"; brand="Lenovo"; owner="baidu"; uid=26118556; platform=android; os=android; lon=120.228549; locationstate=0; location=79,85,2999; osv=4.1.2; maptype=2; cid=79; PPU=UID=26118556&PPK=499276b2&PPT=b490328c&SK=4E2D7FDC8FC5457587B7CCE3941808D10943BAB0D8A7328E4<=1404084541624&UN=selectersky&LV=e5d60885; channelid=446; productorid=1; ua=Lenovo+A820t; X-Wap-Proxy-Cookie=none; uuid=8b9aa8a8-e00e-4746-ad02-60137b6dc88e; apn=WIFI; lat=30.186296; cimei=862326025244100; cversion=5.5.0.1; source="ordinarycate"') content = http.urlcontent('http://jiang.webapp.58.com/placeorder/?jptype=2') print content
def main(): global http http = httpCient() fp = open(json_name,'r') body = fp.read() fp.close() data = json.loads(body) start_key = None start_pos = 0 start_image_pos = 0 if os.path.exists(progress_name): fp = open(progress_name,'r') body = fp.read() arr = body.split(',') if len(arr) != 3: print u'读取进度失败,请确认进度文件的格式是否正确' return start_key = arr[0] start_pos = int(arr[1]) start_image_pos = int(arr[2]) #cate() isFirst = True for key in data: if start_key: if key != start_key and isFirst: isFirst = False continue cateitem(data,key,start_pos,start_image_pos)
def main(): global http http = httpCient() url = 'http://223.6.254.28/wechatSub/wechat_exchangePrizes.action?wechatBean.exchangeType=ct1&wechatBean.entryNo=121923&wechatBean.openId=ouek2ty-w9BCoc6FWA7MOgX-ftJo&wechatBean.question=4&wechatBean.answer=b&wechatBean.code=40ccc86b648ea73d0e12fcec5e4abbc5' content = http.urlcontent(url,None,header) print content
def main(): global http http = httpCient() f = open('result.txt', "w") if login('username','passwd'): page = pagecount while page>0: list = listid(page) f.writelines(x+"\n" for x in list) page = page - 1 print u'所有操作已经完成,结果保存在当前目录result.txt文件中' f.close()
def main(): global http header = {'User-Agent':'Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; Coolpad 5892 Build/JLS36C) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 MicroMessenger/6.0.0.56_r856074.501 NetType/WIFI'} http = httpCient() fenxiao = 'http://223.6.254.28/wechatSub/wechat/wechat_rule.jsp?entryNo=66330&from=singlemessage&isappinstalled=0' toupiao = 'http://223.6.254.28/wechatSub/wechat_activityVoteLink.action?openId=ouek2t9ZDd46KKd9dh9DCRcVdlv' querytoupiao = 'http://223.6.254.28/wechatSub/wechat_activitySubEntryNo.action?entryNo=66330&openId=ouek2t9ZDd46KKd9dh9DCRcVdlvY' #发送顶信息,opoenid必须是已经关注了大华 sendtoupiao = 'http://223.6.254.28/wechatSub/wechat_activityVote.action?openId=ouek2t9ZDd46KKd9dh9DCRcVdlvY&entryNo=66330' url = sendtoupiao #http://223.6.254.28/wechatSub/wechat_activityVoteLink.action?openId=ouek2t9ZDd46KKd9dh9DCRcVdlvY #url = 'http://223.6.254.28/wechatSub/wechat_activityInfo.action?openId=ouek2t-qpWCkslMayIPn7O2NYgF4' content = http.urlcontent(url,None,header) print content.decode('utf-8').encode('gb2312')
def main(): global http, totalAddNum root = os.path.split(os.path.realpath(__file__))[0] totalAddNum = 0 http = httpCient() if not os.path.exists(downloadspath): os.mkdir(downloadspath) l = list() if l: for r in l: s = detail(r) if s: name = s['id'] + '_1440p.mp4' fullpath = os.path.join(downloadspath, name) if os.path.exists(fullpath): print 'file is exists,skip' continue cmd = 'wget -P %s %s' % (downloadspath, s['url']) os.system(cmd)
def main(): http = httpCient(False, None, '127.0.0.1:8888') #只要修改此项即可 bduss = 'k5RlZXT21rZ0ZFcTBqNkpOYk9WeUpwZTlvZEFWRGluQklDSVA2alFqMXNqYVpUQVFBQUFBJCQAAAAAAAAAAAEAAAAif-dAxaPK09PuAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGwAf1NsAH9TUD' baiduid = '68B964621D95CB444623D62988E0BAC3' h_ps_pssid = '5019_6405_6249_1449_5225_6583_6506_6477_4760_6017_6428_6438_6633_6530_6449' cookie = cookielib.Cookie(0, 'BAIDUID', baiduid, None,False, 'baidu.com', False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'BDUSS', bduss, None,False, 'baidu.com', False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'H_PS_PSSID', h_ps_pssid, None,False, 'baidu.com', False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) url = 'http://pan.baidu.com/api/download?channel=chunlei&clienttype=0&web=1&bdstoken=734a3d0422d166edb8973f6ca7a176fd' data = {'sign':'cgUrEHmMvPID6cds052jqnCOuDirfMbePV4sa8Nk5hVMBXMM+Q64YA==','timestamp':'1400832481','fidlist':'[48096015592988]','type':'dlink'} content = http.urlcontent(url , data) print content
def main(): global http lastUsername = lastPassword = None # http = httpCient(False,None,"127.0.0.1:8888") http = httpCient() global charset, cellStatusNum charset = sys.getfilesystemencoding() if not os.path.isfile(file): showmsg("数据库文件 %s 在当前目录不存在,请确认" % file) return try: xls = xlrd.open_workbook(file) table = xls.sheets()[0] cellStatusNum = table.ncols - 2 except: showmsg("打开数据库文件 %s 失败,请确认有操作权限" % file) return global xmlWrite, xmlWriteTable try: xmlWrite = copy(xls) xmlWriteTable = xmlWrite.get_sheet(0) except: showmsg("创建数据库读写对象失败,请确认数据表格式") return nrows = table.nrows if nrows <= 1: showmsg("没有找到可操作的记录,自动退出") return succ = 0 for i in range(nrows): # row = table.row_values(i) # status = row[cellStatusNum] # if len(status)>0: # continue # 跳过第一行 if i == 0: continue # 0为序号,直接跳过 username = stringByCell(table, i, 1, "用户名") if not username: continue password = stringByCell(table, i, 2, "密码") if password == False: continue title = stringByCell(table, i, 3, "标题") if not title: continue biaoqian = stringByCell(table, i, 4, "标签") if not biaoqian: continue pic = stringByCell(table, i, 5, "图片1") if not pic: continue pic2 = stringByCell(table, i, 6, "图片2", False) pic3 = stringByCell(table, i, 7, "图片3", False) pic4 = stringByCell(table, i, 8, "图片4", False) desc = stringByCell(table, i, 9, "描述") if not desc: continue num = intByCell(table, i, 10, "数量") if not num: continue weight = intByCell(table, i, 11, "重量", False) if not weight: weight = "" else: weight = str(weight) picContent = stringByCell(table, i, 12, "内容图片", False) # 判断是否需要登录 上一次成功的用户密码不一样,则要登录 if lastUsername != username or lastPassword != password: http.cleanCookie() result = login(username, password) if not result[0]: showResult(i, result[1]) continue lastUsername = username lastPassword = password # 上传每一个图片 第一个图片必须 result = upload(pic) # result = [True,"i003/2014/08/03/85/small_c5ca221a97aed66a22e7f9db84c9fe61.png","i003/2014/08/03/85/small_c5ca221a97aed66a22e7f9db84c9fe61.png"] if not result[0]: showResult(i, result[1]) continue smallpic = result[1] originalpic = result[2] # 设置内容图片 if picContent: result = uploadContent(picContent) if result[0]: originalpic = result[1] desc = desc + '<br /><img src="' + originalpic + '" />' else: desc = desc + '<br /><img src="' + originalpic + '" />' smallpic2 = "" if pic2: result = upload(pic2) if result[0]: smallpic2 = result[1] originalpic = result[2] if not picContent: desc = desc + '<br /><img src="http://images.onccc.com/' + originalpic + '" />' smallpic3 = "" if pic3: result = upload(pic3) if result[0]: smallpic3 = result[1] originalpic = result[2] if not picContent: desc = desc + '<br /><img src="http://images.onccc.com/' + originalpic + '" />' smallpic4 = "" if pic4: result = upload(pic4) if result[0]: smallpic4 = result[1] originalpic = result[2] if not picContent: desc = desc + '<br /><img src="http://images.onccc.com/' + originalpic + '" />' result = post(title, [smallpic, smallpic2, smallpic3, smallpic4], title, desc, num, weight, biaoqian) if not result[0]: showResult(i, result[1]) continue showResult(i) succ = succ + 1 # table.flush_row_data() # xls.save(file) try: if os.path.isfile(result_file): os.remove(result_file) xmlWrite.save(result_file) except: showmsg("写入结果数据失败") showmsg("所有操作已经完成,共有记录 %d 条,成功上传 %d 条,结果保存在 %s 文件中" % (nrows - 1, succ, result_file))
def main(): global http,option http = httpCient(True) domain = '58.com' cookie = cookielib.Cookie(0, 'isfirst', 'true', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'cookieuid1', '05dvUVOk3HAxiF/EDZ3FAg==', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'showcountdown', 'true', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, '_TCN', 'C4E61ED0AFABBBB66D915DE5AD94645E', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'operate', 'nofilter', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'id58', '"05dz8VOwoTdNBXV8C0QNAg=="', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'www58com', '"AutoLogin=false&UserID=26118556&UserName=selectersky&CityID=0&Email=&AllMsgTotal=0&CommentReadTotal=0&CommentUnReadTotal=0&MsgReadTotal=0&MsgUnReadTotal=0&RequireFriendReadTotal=0&RequireFriendUnReadTotal=0&SystemReadTotal=0&SystemUnReadTotal=0&UserCredit=0&UserScore=0&PurviewID=&IsAgency=false&Agencys=null&SiteKey=2A31A22D9706340595FC6E8F6DD0DB15052A0657EA27860B0&Phone=&WltUrl=&UserLoginVer=4E2D7FDC8FC545758763CE1E8F414D1CE<=1404084541614"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, '58cooper', '"userid=26118556&username=selectersky&cooperkey=3f35337885089d3c6e0479298454d8dd"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, '58passport', '"14040845411548924313622024&7A8AA9BF524FE0547A4BAEE92E17DCD64&f37e36"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'm', '"98%3Aff%3Ad0%3A89%3A00%3A7a"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'r', '"540_960"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'brand', '"Lenovo"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'owner', '"baidu"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'uid', '26118556', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'platform', 'android', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'os', 'android', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'lon', '25.228549', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'locationstate', '0', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'location', '79,85,2999', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'osv', '4.1.2', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'maptype', '2', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'cid', '79', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'PPU', 'UID=26118556&PPK=499276b2&PPT=b490328c&SK=4E2D7FDC8FC5457587B7CCE3941808D10943BAB0D8A7328E4<=1404084541624&UN=selectersky&LV=e5d60885', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'channelid', '446', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'productorid', '1', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'ua', 'Lenovo+A820t', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'X-Wap-Proxy-Cookie', 'none', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'uuid', '8b9aa8a8-e00e-4746-ad02-60137b6dc88e', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'apn', 'WIFI', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'lat', '36.186296', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'cimei', '862326025244100', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'cversion', '5.5.0.1', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) cookie = cookielib.Cookie(0, 'source', '"ordinarycate"', None,False, domain, False, False, '/', True, False, None, True, None, None, {}, rfc2109=False) http.setCookie(cookie) last = 1404104388+60*50 i = 0 while(True): if time.time()>last or i>10: i = 0 content = http.urlcontent('http://jiang.webapp.58.com/placeorder/?jptype=2') print content else: i += 1 time.sleep(1)
def main(): global http,option,token usage = u"根据医生下单:%prog -s -n 沈瑞林 -u 432524198412219014 -p Jokenchen\n查询科室下可用号:%prog -i 浙江大学医学院附属第二医院 -j 内科" version = u"1.0" parser = OptionParser(usage) parser.add_option("-u","--username",dest="username",help=u"登录用户名 只有实际预约时有用",default='') parser.add_option("-p","--password",dest="password",help=u"登录密码 只有实际预约时有用",default='') parser.add_option("-n","--name",dest="name",help=u"名字,如果为空,则必须指定depid,这时为查询该科室下所有医生空名额",default='') parser.add_option("-t","--type",dest = "type", help=u'类型 1为专家 2为普通 3为所有,默认为所有',default=3) parser.add_option("-d","--depid",dest="deptId",help=u'科室ID,必须为大于等于0的数字,如果没有指定或为0,则根据name自动查询,建议只有在医生重名时使用',default=0) parser.add_option("-s", "--submit",action="store_true", dest="submit", default=False,help=u"自动提交订单") parser.add_option('-a','--again',action='store_true', dest="again", default=False,help=u'自动重复查询') #查询类参数 一次只能使用一次查询 parser.add_option('-k',"--doctor",dest="doctor",help=u'根据医生名字查询医生的信息') parser.add_option("-i","--hosname",dest="hosname",help=u'根据医院名称查询医院列表ID') parser.add_option('-j','--deptname',dest="deptname",help=u'科室名称,必须和hosname或hosid配合使用') parser.add_option('-l',"--hosid",dest="hosId",help=u'根据医院ID查询所有的科室ID') parser.add_option('-x','--proxy',dest='proxy',help=u'代理地址 格式如127.0.0.1:8087') (option,args) = parser.parse_args() #输入参数编码转换 转换到Unicode下使用 windows环境命令行下使用了gb2312编码,而linux环境下是utf8编码 charset = 'utf8' if isWin(): charset = 'gb2312' if option.name: option.name = option.name.decode(charset) if option.doctor: option.doctor = option.doctor.decode(charset) if option.hosname: option.hosname = option.hosname.decode(charset) if option.deptname: option.deptname = option.deptname.decode(charset) if option.proxy: http = httpCient(False,None,option.proxy) else: http = httpCient() if option.hosId: queryDepIdByHos(option.hosId) return if option.hosname and not option.deptname: queryHosIdByName(option.hosname) return if option.doctor: queryDepIdByDoctor(option.doctor) return # if not option.name and not option.deptId: # print u'--name参数和--depid参数必须指定一个' # return #只指定了科室名,则根据医院名称或医院ID自动查询该科室下的所有可用号 if option.deptname and not option.deptId and not option.name: #没有指定医院ID 则去自动查询,然后取第一条记录 if not option.hosId and not option.hosname: print u'指定了deptName,则hosId或hosName任指定一个' return #没有指定hosId,则根据医院名称自动查询 如果有多个医院匹配,只会选择第一个医院 hosName = None if not option.hosId: data = queryHosIdByName(option.hosname, False) if not data: print u'没有找到医院 %s 任何信息,请确认输入正确' % option.hosname return data = data['searchList'] row = data['result'][0] option.hosId = row['hosCode'] hosName = row['hosName'] print u'匹配医院:%s,共有 %d 个结果' % (hosName, len(data['result'])) #根据hosId和deptName匹配科室 data = queryDepIdByHos(option.hosId, False) if not data: print u'医院 %s 没有找到任何科室信息' % hosName return for row in data: print u'匹配医院:%s,匹配科室:%s,科号:%s' % (hosName, row['deptName'], row['deptId']) #break #选择第一条记录 option.deptId = data[0]['deptId'] if option.again: while True: data = queryRemainByName(option.name, option.type, option.deptId) if data['code'] == 0: break; else: print data['msg'] sleep_time = random.random()*2 time.sleep(sleep_time) else: data = queryRemainByName(option.name, option.type, option.deptId) if data['code'] != 0: print data['msg'] else: #只是查询 if not option.submit: print u'\n%10s %10s %10s %10s %10s'%(u'科号', u'名称', u'类型', u'时间', u'费用') print u'---------------------------------------------------------------------' for row in data['data']: print u'%10s %10s %10s %10s %10s' % (option.deptId,row['docName'],row['docTitle'],row['date'],row['regFee']) print u'---------------------------------------------------------------------' return hosId = data['hosId'] hosName = data['hosName']; deptId = data['deptId'] #使用第一个号来预约 data = data['data'][0]; #登录 获取token re = login(option.username,option.password) if re['code'] == u'0': token = re['data']['token'] else: print u'登录失败,原因:%s' % re['message'] return #查询具体号的信息 re = QueryNumResourceListForPat(data['schemeId'], data['resDate'], data['resTimeSign']) if not re: print u'查询号具体信息失败,请确认网络是否已经连接' return #多个号信息,只选第一个 list = re['numList']; pat = list[0] numId = pat['numId'] #查询验证码,显示验证码 image = queryImageCode(hosId, numId) if not image: print u'获取验证码失败,请确认网络是否已经连接' return image.show() #等待用户输入看到的验证码 ch = raw_input("enter image code:") #提交订单 #numResourceId, docId, docName, hosName, hosId, deptId, schemeId, orderTime, orderTimeSign, orderNumber, deptName, resDate, orderCode re = submitOrder(numId, data['docId'], data['docName'], hosName, hosId, deptId, data['schemeId'], pat['resTime'], data['resTimeSign'], pat['resNumber'], data['deptName'], data['resDate'], ch) if re['code'] != u'0': print u'操作失败,原因:%s' % re['message'] else: print u'恭喜,操作成功,取号密码:%s,稍候有短信发到你的手机' % re['data']['takeCode']
def main(): global http lastUsername = lastPassword = None #http = httpCient(False,None,"127.0.0.1:8888") http = httpCient() global charset,cellStatusNum charset = sys.getfilesystemencoding() if not os.path.isfile(file): showmsg("数据库文件 %s 在当前目录不存在,请确认" % file) return try: xls = xlrd.open_workbook(file) table = xls.sheets()[0] cellStatusNum = table.ncols - 2 except: showmsg("打开数据库文件 %s 失败,请确认有操作权限" % file) return global xmlWrite,xmlWriteTable try: xmlWrite = copy(xls) xmlWriteTable = xmlWrite.get_sheet(0) except: showmsg("创建数据库读写对象失败,请确认数据表格式") return nrows = table.nrows if nrows<=1: showmsg("没有找到可操作的记录,自动退出") return succ = 0 for i in range(nrows ): #row = table.row_values(i) # status = row[cellStatusNum] # if len(status)>0: # continue #跳过第一行 if i==0:continue #0为序号,直接跳过 username = stringByCell(table,i,1,"用户名") if not username:continue password = stringByCell(table,i,2,"密码") if password == False:continue #判断是否需要登录 上一次成功的用户密码不一样,则要登录 if lastUsername != username or lastPassword != password: http.cleanCookie() result = login(username, password) if not result[0]: showResult(i, result[1]) continue lastUsername = username lastPassword = password #7行则认为是更新产品 re = 0 if table.ncols == 7: re = processUpdate(table,i) if re: succ += re else: re = processUpload(table,i) if re: succ = succ + re #table.flush_row_data() #xls.save(file) try: if os.path.isfile(result_file): os.remove(result_file) xmlWrite.save(result_file) except: showmsg("写入结果数据失败") showmsg("所有操作已经完成,共有记录 %d 条,成功操作 %d 条数据,结果保存在 %s 文件中"% (nrows-1,succ,result_file))
#! /usr/bin/env python #coding=utf-8 # -*- coding: utf-8 -*- import string from Cjx.http import httpCient __author__ = 'appie' http = httpCient(True,None,"202.106.16.36:3128") #第条产品信息正则 repxStr = "j_normal(.*?)j_shadow" #总共分页数正则 pageCountRepxStr = "共([0-9]*?)页" #要获取的产品信息正则 detailDict = { 'price':'<span>(.*?)</span>', 'url':'href=\"(.*?)\"', 'title':'title=\"(.*?)\"', 'img':'src=\"(.*?)\"' } alllist = [] url = "http://www.24home.com/productList/33-0-0-0-3-0-49-1-1.htm" content = http.urlcontent(url) list = http.itemlist(content,repxStr,0,pageCountRepxStr) #处理每个产品数据 pro_data = list['list'] print len(pro_data) if len(pro_data) > 0: for item in pro_data: #获取产品详细信息 detail = http.itemDetail(item,detailDict)
def main(): global http #http = httpCient(False,None,"192.168.22.120:8888") http = httpCient() global charset charset = sys.getfilesystemencoding() if not os.path.isfile(file): showmsg(u"数据库文件 %s 在当前目录不存在,请确认" % file) return try: xls = xlrd.open_workbook(file) table = xls.sheets()[0] except: showmsg(u"打开数据库文件 %s 失败,请确认有操作权限" % file) return global xmlWrite, xmlWriteTable try: xmlWrite = copy(xls) xmlWriteTable = xmlWrite.get_sheet(0) except: showmsg(u"创建数据库读写对象失败,请确认数据表格式") return nrows = table.nrows if nrows<3: showmsg(u"没有找到可操作的记录,自动退出") return succ = 0 for i in range(nrows ): #row = table.row_values(i) # status = row[cellStatusNum] # if len(status)>0: # continue #跳过第一行和第二行 if i==0 or i==1:continue #0为序号,直接跳过 username = stringByCell(table,i,1,u"用户名") if not username:continue oldpassword = stringByCell(table,i,2,u"旧密码") if not oldpassword:continue newpassword = stringByCell(table,i,3,u"新密码") if not newpassword:continue result = login(username, oldpassword) if not result[0]: showResult(i, result[1]) continue result = post(oldpassword, newpassword) if result[0] == False: showResult(i, result[1]) continue showResult(i) succ = succ + 1 #table.flush_row_data() #xls.save(file) try: if os.path.isfile(result_file): os.remove(result_file) xmlWrite.save(result_file) except: showmsg(u"写入结果数据失败") showmsg(u"所有操作已经完成,共有记录 %d 条,成功操作 %d 条,结果保存在 %s 文件中"% (nrows-2,succ,result_file))