最近做性能测试,写了个python程序自动将URL里面的‘%2B’,‘20%’,‘3B'等转换成正常字符,方便查看。

import os,sys;

path = sys.path[0]
os.chdir(path)
encode_list = 'encode_list.txt'
result = path + '\\results' def get_encode():
encode_file = open(path + '\\'+ encode_list)
encode = dict()
for line in encode_file:
if line!='\n' and len(line) >1:
if line.find('read me') <0:
encode[line[1:].strip()] = line[0]
return encode def get_files():
files = os.listdir(path)
file_list = list()
for file in files:
if file.endswith('.txt') and file!= encode_list:
file_list.append(file)
return file_list def relace_url_encode(strPri,dicEncode):
items = dicEncode.items()
for (key,value) in items:
if strPri.find(key):
strPri = strPri.replace(key,value)
return strPri def create_result():
if not os.path.isdir(result):
os.makedirs(result) def write_result(filePri,strText):
fp = open(result+'\\'+filePri,'w+')
fp.write(strText)
fp.close() create_result()
encode = get_encode()
file_list = get_files()
for ff in file_list:
try:
f = open(ff)
text = f.read()
finally:
f.close()
temp = relace_url_encode(text,encode)
temp = temp.replace('&','\n')
write_result(ff,temp)

下面是文件夹结构:

encode.py的代码贴在上面

encode_list.txt里面装的是转换对照表,其中文件名是hard code在python程序里面的,最好不要改

前面的是正常字符,后面的是需要转换的字符

需要转码的URL形如下面的形式:

selectForm=selectForm&publishId=iphone6SapptR&color=%7B%22colorDisplayText%%3A%22Grey%%2C%22colorId%%3A%22Grey%%2C%22publishId%%3A%22iphone6SapptM%%2C%22modelCode%%3A%22iphone6SmodelM%%2C%22available%%3Atrue%7D&rom=%7B%22capacityDisplayText%%3A%2216GB%%2C%22capacityId%%3A%2216GB%%2C%22imageFileName%%3A%22iPhoneX-gold.png%%2C%22publishId%%3A%22iphone6SapptM%%2C%22modelCode%%3A%22iphone6SmodelM%%2C%22available%%3Atrue%7D&locationId=%7B%22locationId%%3A%22Marina_Bay_Sands_Exhibition_Hall_A%%2C%22locationDisplayText%%3A%22Marina%20Bay%20Sands%20Exhibition%20Hall%20A%%2C%22publishId%%3A%22iphone6SapptM%%2C%22available%%3Atrue%7D&dateId=&timeId=&javax.faces.ViewState=H4sIAAAAAAAAAE1QO0sDQRAeL7n4RGIEK9PZWLhgJ1hoQIOH8YGgCBa6uVuTC3e76z5ydxaBNFrYWGhhIVpY5k%2BIhZ2gpZXYW9u6F0LiBzvMst9jZjs%2FYHMpYKqBmxhp5QdoA8v6Fub28Ofzy8zJewasMowFDHtl7ComHBhVdUFknQVezFdWIcVENGJq3hxLwazLQiQ1RafYJRKtJRSHvltylc%2BoNFnTg6ySEDip%2BFLF7Y%2Fi3Su%2Bz8CQA1npn5OYp8ZRNq2xArtx7HuL2qiPKl19gGkN7VQ
bxFXL12%2BHD3k5H1iGmsosfQYtyJnO5gb9W6YlYCFVx73ZzKScUUIV2ncOfBLtMabmdgXjRKhkkyQSeigYZwGTg%2BR1qsP%2Fj1xBLsBSOV7%2FN7s8hypSI6Lw%2Ffj0275cstL97CYONDF%2B%2BQFvW4dVIi46t8Xxm6%2Br%2FiKcx3%2FTRn8XowEAAA%3D%3D&javax.faces.source=color%3A1&javax.faces.partial.event=change&javax.faces.partial.execute=color%20color%3A1&javax.faces.partial.render=productImage%20rom%20timeId%20dateId%20locationId&javax.faces.behavior.event=change&javax.faces.partial.ajax=true

我把转码过的结果全部放在result文件夹里面,双击运行,所有的txt文件都会被转码。并且该文件夹随便放在哪里,代码均可以执行。
转码过后:

selectForm=selectForm
publishId=iphone6SapptR
color={"colorDisplayText":"Grey","colorId":"Grey","publishId":"iphone6SapptM","modelCode":"iphone6SmodelM","available":true}
rom={"capacityDisplayText":"16GB","capacityId":"16GB","imageFileName":"iPhoneX-gold.png","publishId":"iphone6SapptM","modelCode":"iphone6SmodelM","available":true}
locationId={"locationId":"Marina_Bay_Sands_Exhibition_Hall_A","locationDisplayText":"Marina_Bay_Sands_Exhibition_Hall_A","publishId":"iphone6SapptM","available":true}
dateId=
timeId=
javax.faces.ViewState=H4sIAAAAAAAAAE1QO0sDQRAeL7n4RGIEK9PZWLhgJ1hoQIOH8YGgCBa6uVuTC3e76z5ydxaBNFrYWGhhIVpY5k+IhZ2gpZXYW9u6F0LiBzvMst9jZjs/YHMpYKqBmxhp5QdoA8v6Fub28Ofzy8zJewasMowFDHtl7ComHBhVdUFknQVezFdWIcVENGJq3hxLwazLQiQ1RafYJRKtJRSHvltylc+oNFnTg6ySEDip+FLF7Y/i3Su+z8CQA1npn5OYp8ZRNq2xArtx7HuL2qiPKl19gGkN7VQ
bxFXL12+HD3k5H1iGmsosfQYtyJnO5gb9W6YlYCFVx73ZzKScUUIV2ncOfBLtMabmdgXjRKhkkyQSeigYZwGTg+R1qsP/j1xBLsBSOV7/N7s8hypSI6Lw/fj0275cstL97CYONDF++QFvW4dVIi46t8Xxm6+r/iKcx3/TRn8XowEAAA==
javax.faces.source=color:1
javax.faces.partial.event=change
javax.faces.partial.execute=color_color:1
javax.faces.partial.render=productImage_rom_timeId_dateId_locationId
javax.faces.behavior.event=change
javax.faces.partial.ajax=true

转换后就可以更方便的查找对比,方便测试进行。

应该还有需要改进的地方,如果测试需要,再做改进。

性能测试URL自动转码的更多相关文章

  1. 百度移动搜索自动转码太坑爹,JS跳转地址会被抓取

    这段时间碰到个很崩溃的问题,一个页面通过 script 加载请求服务端进行统计再输出js进行跳转,分为两个步骤分别统计, 打开页面通过script 请求远程服务器进行统计并输出要通过js使页面跳转的最 ...

  2. window.location.hash在firefox下中文自动转码为UTF-8问题

    1.window.location.hash window.location.hash这个属性主要是读取和写入网页位置的,我们经常会用来控制网页单页面跳转或者是控制网页位置.然而这个属性在firefo ...

  3. 安装完magento后,其他电脑无法访问magento,URL自动跳转到http://localhost/magento

    问题:在电脑A上安装完了magento 1.7.0.2 然后, 在电脑A上用 http://localhost/magento 访问网站,没有问题. 但在电脑B 上用 http://192.168.4 ...

  4. URL中文转码问题

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  5. nginx url自动加斜杠的问题

    nginx url自动加斜杠问题及301重定向 时间:2016-02-04 15:14:28来源:网络 导读:nginx url自动加斜杠问题及301重定向,URL指向一个目录并且在最后没有包含斜杠, ...

  6. idea unicode自动转码设置

    idea unicode自动转码设置 File > Settings > Editor > File Encodings 右侧 Properties Files 中 选中 Trans ...

  7. (原创)如何在性能测试中自动生成并获取Oracle AWR报告

    版权声明:本文为原创文章,转载请先联系并标明出处 由于日常使用最多的数据库为Oracle,因此,最近又打起了Oracle的AWR报告的主意. 过去我们执行测试,都是执行开始和结束分别手动建立一个快照, ...

  8. Yii2 在模块modules间跳转时,url自动加模块名

    如目的地址product/detail, 当前模块是admin, 访问时如果目的url'product/detail',会变成'admin/product/detail'. 解决方法:url改成'/p ...

  9. php Yii2图片的url自动加localhost

    解决方法:在地址前加http://,这样url就是绝对地址,不加的话是相对地址,游览器会自动转换,即加localhost

随机推荐

  1. poj2492--A Bug&#39;s Life(并查集变形)

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 28703   Accepted: 9350 De ...

  2. 在fragment中显示对话框出现异常

    异常类型为:android.view.WindowManager$BadTokenException: Unable to add window 我在fragment中public View onCr ...

  3. [LeetCOde][Java] Best Time to Buy and Sell Stock III

    题目: Say you have an array for which the ith element is the price of a given stock on day i. Design a ...

  4. JS冒泡事件 与 事件捕获

    JS冒泡事件 与 事件捕获 案例 <!DOCTYPE html> <html> <head> <title>冒泡事件</title> < ...

  5. BZOJ 2844 高斯消元 线性基

    思路: //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using ...

  6. Ubuntu16.04下Mongodb官网卸载部署步骤(图文详解)(博主推荐)

    不多说,直接上干货! 前期博客 Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐) https://docs.mongodb.com/manual/tutorial/ins ...

  7. html5+css3+javascript 自定义弹出窗口

    效果图: 源码: 1.demo.jsp <%@ page contentType="text/html;charset=UTF-8" language="java& ...

  8. LeetCode hard 668. Kth Smallest Number in Multiplication Table(二分答案,一次过了,好开心,哈哈哈哈)

    题目:https://leetcode.com/problems/kth-smallest-number-in-multiplication-table/description/ 668. Kth S ...

  9. 乌班图 之 Ubuntu 16.04 LTS连接无线上网炒鸡慢问题!!!

    用VMware装了Ubuntu 16.04 LTS后连接无线上网,发现出奇的慢. 果断感觉有问题,立马找度娘,果然有问题!!! 网上查找亲测有效的方法为: 在终端运行:sudo gedit /etc/ ...

  10. 【原创】关于JMS[1]

    面向消息中间件(MOM)为分布式系统提供异步,解耦,稳定,可扩展和安全的行为.MOM在分布式计算领域是一个重要的概念.它允许应用使用代理器API在分布式环境实现各种功能.Java消息服务(Java M ...