python request调试助手并且生成py代码 残次品

闲得无聊整的,有闲心的大佬麻烦完善下

预想的是request(读取返回图片 可选编码,重定向等等)  编码解码  正则调试(加入常用正则语句)  json树形解析(生成py代码) 常用算法加解密(可选浏览器引擎,nodev8,浏览器运行)(哈希系列 hmac系列 aes des 3des rsa)

requests页面雏形没写完就不想弄了

import wx
import requests
import json
import win32con
import win32clipboard

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, title='晨梦调试助手', size=(749, 806),name='frame',style=541072384)
        self.window = wx.Panel(self)
        self.Centre()
        self.listShow = wx.ComboBox(self.window,value='get',pos=(25, 20),name='comboBox',choices=['get', 'post'],style=16)
        self.listShow.SetSize((61, 27))
        self.table = wx.StaticText(self.window,size=(55, 23),pos=(101, 24),label='url:',name='staticText',style=2321)
        self.urlInput = wx.TextCtrl(self.window,size=(418, 25),pos=(164, 20),value='',name='text',style=256)
        self.table2 = wx.StaticText(self.window,size=(74, 22),pos=(23, 76),label='请求body:',name='staticText',style=2321)
        self.dataInput = wx.TextCtrl(self.window,size=(699, 114),pos=(25, 109),value='',name='text',style=1073741856)
        self.table3 = wx.StaticText(self.window,size=(62, 21),pos=(18, 229),label='请求头:',name='staticText',style=2321)
        self.headersInput = wx.TextCtrl(self.window,size=(696, 120),pos=(27, 255),value='',name='text',style=1073741856)
        self.tabl4 = wx.StaticText(self.window,size=(75, 21),pos=(28, 381),label='提交cookie:',name='staticText',style=2321)
        self.cookieInput = wx.TextCtrl(self.window,size=(693, 115),pos=(30, 406),value='',name='text',style=1073741856)
        self.sendBtn = wx.Button(self.window,size=(64, 27),pos=(595, 21),label='请求',name='button')
        self.scBtn = wx.Button(self.window,size=(56, 26),pos=(661, 21),label='生成',name='button')

        self.sendBtn.Bind(wx.EVT_BUTTON, self.run)
        self.scBtn.Bind(wx.EVT_BUTTON, self.sc)
        self.session = None
        self.response = None

    def initHeaders(self,text,cookie):
        headers = {}
        arr = text.strip().split("\n")
        if not arr:
            return ""
        for i in arr:
            if ":" in i:
                arr1 = i.split(": ")
                headers[arr1[0]] = arr1[1]
            else:
                continue
        if cookie:
            headers['cookie'] = cookie
        return headers

    def is_json(self,myjson):
        try:
            json_object = json.loads(myjson)
        except ValueError as e:
            return False
        return True

    def sc(self, even):
        url = self.urlInput.GetValue()
        data = self.dataInput.GetValue()
        cookie = self.cookieInput.GetValue()
        headers = self.initHeaders(self.headersInput.GetValue(), cookie)
        if not data:
            data = None

        text = ""
        text += f'headers = {json.dumps(headers)}\n\n'
        text += f'url = "{url}"\n\n'
        if data ==  None:
            text += f'data = {data}\n\n'
        else:
            text += f'data = "{data}"\n\n'
        s = ""
        if self.listShow.GetValue() == 'get':
            s = f'requests.get(url=url,headers=headers)'
        elif self.listShow.GetValue() == 'post':
            if 'application/json' in self.headersInput.GetValue().lower() and self.is_json(data):
                s = f'requests.post(url=url,json=json.loads(data), headers=headers)'
            elif '=' not in data:
                s = f'requests.post(url=url, params=data, headers=headers)'
            else:
                s = f'requests.post(url=url, data=data, headers=headers)'

        win32clipboard.OpenClipboard()
        win32clipboard.SetClipboardData(win32con.CF_UNICODETEXT, f'{text}response = {s}\nresult = response.text\nprint(result)')
        win32clipboard.CloseClipboard()



    def run(self,even):
        self.session = requests.session()

        url = self.urlInput.GetValue()
        data = self.dataInput.GetValue()
        cookie = self.cookieInput.GetValue()
        headers = self.initHeaders(self.headersInput.GetValue(),cookie)

        if self.listShow.GetValue() == 'get':
            self.response = self.session.get(url=url,headers=headers)
        elif self.listShow.GetValue() == 'post':
            if 'application/json' in self.headersInput.GetValue().lower() and self.is_json(data):
                self.response = self.session.post(url=url,json=json.loads(data), headers=headers)
            elif '=' not in data:
                self.response = self.session.post(url=url, params=data, headers=headers)
            else:
                if not data:
                    data = None
                self.response = self.session.post(url=url, data=data, headers=headers)

        print(self.response.text)


class myApp(wx.App):
    def  OnInit(self):
        self.frame = Frame()
        self.frame.Show(True)
        return True

if __name__ == '__main__':
    app = myApp()
    app.MainLoop()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值