最近做性能测试,写了个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. 【源代码】将一个整数的每位数分解并按逆序放入一个数组中(用递归算法)(C语言实现)

    帮朋友做的,好像是一个面试题.假设不过考察递归的话.应该是够了,程序的健壮性和通用性都非常一般的说-- #include <stdio.h> #include <stdlib.h&g ...

  2. C++ STL之list具体解释

    list容器是一个双向链表,能够高效地进行插入删除元素. 构造函数 list<Elem> c;//空list list<int> c(3);//创建一个含有三个默认值是0的元素 ...

  3. CentOS 6.5 下编译安装 Nginx 1.8.0

    转自:https://i.cnblogs.com/EditPosts.aspx?postid=8303227&update=1 安装编译依赖的包 yum -y install gcc gcc- ...

  4. POJ 3261 后缀数组+二分

    思路: 论文题- 二分+对后缀分组 这块一开始不用基数排序 会更快的(其实区别不大) //By SiriusRen #include <cstdio> #include <cstri ...

  5. ETL工具的功能和kettle如何来提供这些功能

    不多说,直接上干货! 大家会有一个疑惑,本系列博客是Kettle,那怎么扯上ETL呢? Kettle是一款国外开源的ETL工具,纯java编写,可以在Window.Linux.Unix上运行. 说白了 ...

  6. CSS中元素各种居中方法(思维导图)

    前言 用思维导图的方式简单总结一下各种元素的居中方法,如下图: 补充一下: table自带功能 100% 高度的 afrer before 加上 inline block优化 div 装成 table ...

  7. FCC高级编程之Inventory Update

    Inventory Update Compare and update the inventory stored in a 2D array against a second 2D array of ...

  8. Java中hashCode与equal方法详解

    转载自http://blog.csdn.net/jiangwei0910410003/article/details/22739953 Java中的equals方法和hashCode方法是Object ...

  9. 写入~/.bashrc 文件

    1.进入~/.bashrc 文件 vim ~/.bashrc 2.按下I键,然后按Enter键 加入路径 3.按ESC键退出,再按:wq! 保存即可.

  10. 入门python:《Python编程快速上手让繁琐工作自动化》中英文PDF+代码

    入门推荐学习<python编程快速上手>前6章是python的基础知识,通俗易懂地讲解基础,初学者容易犯错的地方,都会指出来.从第三章开始,每章都有一个实践项目,用来巩固前面所学的知识. ...