python url编码与解码
Posted lisa2016
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python url编码与解码相关的知识,希望对你有一定的参考价值。
上代码
1 #codeing:utf-8 2 from urllib import parse 3 4 ori_url_10=‘http://192.168.0.10:3080/asg/portal.do?call=230&json="pri":"search_key":"","f":"f1,f2,f3,f4,f5,f7,f9,f10,f11","sadu":"0","apkversion":"1","imeibak":"868805034766728,868805034854508,A000008C057C25","isInsHwSevice":true,"utd_id":"Wt1InLx\/qxUDAETE+FTqwQkW","czip":"0","supportLoginWay":["QQ","WECHAT","SINA","PHONE_NUM_VERIFY","HUAWEI",null,"GEYAN"],"isLogin":"2","appSign":"09a448c68f8502610a48287073621e9c","clip_info":"","sourceIp":"http:\/\/192.168.0.10:3080\/asg\/portal.do","bookHero":"","v":"1","rCode":"3973004","vtv":"9","bidReqCount":3,"android_id":"441c3a1de1b2ad7d","payDexTime":"2019-04-23 20:20:34","installHours":0,"pub":"clientAgent":"svnVer_1909051616","city":"%E4%BA%B3%E5%B7%9E%E5%B8%82","sign":"ba8e936e5991211c5664bce09d063c1f","screen":"720x1206","appCode":"f002","imsi":"dz_1567589819625","deviceId":"dz4fb51a4614604ad185d390bb40101f00","lsw":"2","apiVersion":"3.9.7.3004","province":"%E5%AE%89%E5%BE%BD%E7%9C%81","model":"ALP-AL00","brand":"HUAWEI","apn":"wifi","channelCode":"Google","dzPaySupport":"2","os":"android28","pname":"com.ishugui","utdid":"Wt1InLx\/qxUDAETE+FTqwQkW","en":"\"adsdk\":\"1\",\"geyan\":\"1\"","channelFee":"Google05","userId":"","p":"59","subPline":"2","afu":"0","cmTel":"","v":"4","imei":"868805034766728","macAddr":"E4:A7:C5:08:8C:5B"‘ 5 6 print(‘----------------------ori_url\n‘,ori_url_10) 7 8 #decode解码 9 urldecode=parse.unquote(ori_url_10) 10 print(‘----------------------urldecode\n‘,urldecode) 11 12 #encode编码 13 urlencode=parse.quote(urldecode) 14 print(‘----------------------urlencode\n‘,urlencode) 15 16 17 18 #批量处理 19 urldecodes=[] 20 #encode编码 21 with open("d:/url.txt") as fr: 22 lines=fr.readlines() 23 i=1 24 for line in lines: 25 print(‘----------------------ori_url\n‘,line) 26 print(‘正在进行%d 个‘%i) 27 i=i+1 28 urldecode=parse.unquote(line) 29 30 urldecodes.append(urldecode) 31 32 print(urldecodes) 33 #decode解码 34 with open("d:/url_decode.txt","w+") as fw: 35 #fw.writelines(urldecodes) 36 37 for i in range(len(urldecodes)): 38 fw.write(urldecodes[i]) 39 fw.write(‘\n‘) 40 print(‘已经写入文件。‘) 41 42 43 44 45 46
以上是关于python url编码与解码的主要内容,如果未能解决你的问题,请参考以下文章