1 Star 1 Fork 0

TY/ApiTest_Platform

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
demo_test.py 4.30 KB
一键复制 编辑 原始数据 按行查看 历史
TY 提交于 2021-03-14 02:53 . fiddler抓包导入功能完成
from urllib.parse import unquote
# str_filename = "31_full.txt"
# 指定文件
# save_name = "re_test.py"
# 修改后缀为py结尾
# save_name = str_filename.replace("txt", "py")
class FidToPy():
def __init__(self, str_filename):
self.str_filename = str_filename
self.method = ""
self.text = ''
self.host = ''
self.url = ""
self.headers = {}
self.cookies = {}
self.data = {}
self.data_method = ''
def get_method(self):
infos = self.text.split("\n")[0]
self.method = infos.split(" ")[0]
def get_host(self):
infos = self.text.split("\n")[0]
url_list = unquote(infos.split(" ")[1]).split('/')
self.host = url_list[0] + '//' + url_list[2] + '/'
def get_url(self):
infos = self.text.split("\n")[0]
s_list = unquote(infos.split(" ")[1]).split('/')
self.url = "/".join(s_list[3:])
def get_headers(self):
infos = self.text.split("\n")[1:]
info = ""
for i in infos:
if "Cookie: " in i:
break
info += i + "\n"
headers = info.split("\n")
while "" in headers:
headers.remove("")
for i in headers:
if ": " not in i:
break
self.headers[i.split(": ")[0]] = i.split(": ")[1]
def get_data_method(self):
self.data_method = self.headers['Content-Type'].split(";")[0]
def get_cookies(self):
infos = self.text.split("\n")[1:]
cookies_flag = 0
for i in infos:
if "Cookie: " in i:
self.cookies = i.replace("Cookie: ", "")
print(self.cookies)
cookies_flag = 1
break
if cookies_flag == 1:
self.cookies = {i.split("=")[0]: i.split("=")[1] for i in self.cookies.split("; ")}
def get_data(self):
try:
infos = self.text.split("\n")
for i in range(2, len(infos)):
if infos[i - 1] == "" and "HTTP" in infos[i + 1]:
self.data = infos[i]
break
self.data = {i.split("=")[0]: unquote(i.split("=")[1]) for i in self.data.split("&")}
except:
pass
# def get_req(self):
# info_beg = "#!/usr/bin/python\n# -*- coding: UTF-8 -*-\nimport requests\n\n"
# info_url = "url = \'{}\'\n".format(self.url[1])
# info_headers = "headers = {}\n".format(self.headers)
# info_cookies = "cookies = {}\n".format(self.cookies)
# info_data = "data = {}\n\n".format(self.data)
# if "GET" in self.url[0]:
# info_req = "html = requests.get(url, headers=headers, verify=False, cookies=cookies)\n"
# else:
# info_req = "html = requests.post(url, headers=headers, verify=False, cookies=cookies, data=data)\n"
# info_end = "print(len(html.text))\nprint(html.text)\n"
# text = info_beg + info_url + info_headers + info_cookies + info_data + info_req + info_end
# with open(save_name, "w+", encoding="utf8") as p:
# p.write(text)
# print("转化成功!!")
# print(save_name, "文件保存!")
def read_infos(self):
with open(self.str_filename, "r+", encoding="utf-8") as p:
old_line = ""
for line in p:
if old_line == b"\n" and line.encode() == b"\n":
break
old_line = line.encode()
self.text += old_line.decode()
# print("self.text:", self.text)
def start(self):
self.read_infos()
self.get_method()
self.get_url()
self.get_host()
self.get_headers()
self.get_cookies()
self.get_data()
self.get_data_method()
print(self.method)
print(self.url)
print(self.host)
print(self.headers)
print(self.cookies)
print(self.data)
print(f"method :{self.data_method}")
# self.get_req()
if __name__ == '__main__':
f = FidToPy("31_full.txt")
f.start()
# s = 'https://mp.weixin.qq.com/mp/wapcommreport?uin=&key=&pass_ticket=&wxtoken=777&devicetype=&clientversion=&__biz=MzA3NTc4Njk1NQ==&appmsg_token=&x5=0&f=json'
#
# s_list = s.split('/')
# print("/".join(s_list[3:]))
# print(s_list[0]+'//'+s_list[2])
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mizuk/api_test_platform.git
git@gitee.com:mizuk/api_test_platform.git
mizuk
api_test_platform
ApiTest_Platform
master

搜索帮助

D67c1975 1850385 1daf7b77 1850385