性能测试URL自动转码
最近做性能测试,写了个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自动转码的更多相关文章
- 百度移动搜索自动转码太坑爹,JS跳转地址会被抓取
这段时间碰到个很崩溃的问题,一个页面通过 script 加载请求服务端进行统计再输出js进行跳转,分为两个步骤分别统计, 打开页面通过script 请求远程服务器进行统计并输出要通过js使页面跳转的最 ...
- window.location.hash在firefox下中文自动转码为UTF-8问题
1.window.location.hash window.location.hash这个属性主要是读取和写入网页位置的,我们经常会用来控制网页单页面跳转或者是控制网页位置.然而这个属性在firefo ...
- 安装完magento后,其他电脑无法访问magento,URL自动跳转到http://localhost/magento
问题:在电脑A上安装完了magento 1.7.0.2 然后, 在电脑A上用 http://localhost/magento 访问网站,没有问题. 但在电脑B 上用 http://192.168.4 ...
- URL中文转码问题
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- nginx url自动加斜杠的问题
nginx url自动加斜杠问题及301重定向 时间:2016-02-04 15:14:28来源:网络 导读:nginx url自动加斜杠问题及301重定向,URL指向一个目录并且在最后没有包含斜杠, ...
- idea unicode自动转码设置
idea unicode自动转码设置 File > Settings > Editor > File Encodings 右侧 Properties Files 中 选中 Trans ...
- (原创)如何在性能测试中自动生成并获取Oracle AWR报告
版权声明:本文为原创文章,转载请先联系并标明出处 由于日常使用最多的数据库为Oracle,因此,最近又打起了Oracle的AWR报告的主意. 过去我们执行测试,都是执行开始和结束分别手动建立一个快照, ...
- Yii2 在模块modules间跳转时,url自动加模块名
如目的地址product/detail, 当前模块是admin, 访问时如果目的url'product/detail',会变成'admin/product/detail'. 解决方法:url改成'/p ...
- php Yii2图片的url自动加localhost
解决方法:在地址前加http://,这样url就是绝对地址,不加的话是相对地址,游览器会自动转换,即加localhost
随机推荐
- HTML---经常使用标签总结与实践
什么是HTML? 超文本标记语言,标准通用标记语言下的一个应用. "超文本"就是指页面内能够包括图片.链接,甚至音乐.程序等非文字元素. 超文本标记语言的结构包含" ...
- Intellij idea 自动完成的变量名称首字母变为小写
Intellij idea 自动完成的变量名称首字母变为小写 好像没有什么好的自动办法,自己输入一个小写的字母吧,然后Idea会出提示.
- Swift开发教程--怎样使UITableViewController背景透明
self.tableView.backgroundView? .backgroundColor = UIColor.clearColor(); self.tableView.backgroundCol ...
- iOS给label加入下划线
UILabel *myLabel = [[UILabelalloc] ,, , )]; NSMutableAttributedString *content = [[NSMutableAttribut ...
- poj 3311 Hie with the Pie (TSP问题)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4491 Accepted: 2376 ...
- javaWeb web.xml 配置
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http:// ...
- maven关于pom文件配置详解(转载)
转载:http://www.cnblogs.com/hafiz <project xmlns="http://maven.apache.org/POM/4.0.0" xmln ...
- Ubuntu16.04下Mongodb官网安装部署步骤(图文详解)(博主推荐)
不多说,直接上干货! 在这篇博客里,我采用了非官网的安装步骤,来进行安装.走了弯路,同时,也是不建议.因为在大数据领域和实际生产里,还是要走正规的为好. Ubuntu16.04下Mongodb(离线安 ...
- Install the high performance Nginx web server on Ubuntu
Look out Apache, there's a web server – Nginx (pronounced Engine X) – that means to dismantle you as ...
- hiho160周 - 字符串压缩,经典dp
题目链接 小Hi希望压缩一个只包含大写字母'A'-'Z'的字符串.他使用的方法是:如果某个子串 S 连续出现了 X 次,就用'X(S)'来表示.例如AAAAAAAAAABABABCCD可以用10(A) ...