吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 2217|回复: 5
收起左侧

[Python 转载] python爬虫header处理小工具源码,需要tkinter

[复制链接]
Clinton 发表于 2020-3-30 22:45
本帖最后由 Clinton 于 2020-4-2 17:12 编辑

前几天看见老哥发了一个,去下载没下载到,就自己写了一个,直接分享源码给大家吧。修复了bug.
import tkinter as tk

class MyApp(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title('header理工具')
        win_width = self.winfo_screenwidth()
        win_height = self.winfo_screenheight()
        my_width = 800
        my_height = 560
        x = (win_width - my_width) / 2
        y = (win_height - my_height) / 2
        self.geometry("%dx%d+%d+%d" % (my_width, my_height, x, y))
        self.maxsize(my_width, my_height)
        self.minsize(my_width, my_height)
        self.button = tk.Button(self, text='转换', font=('', 12), command=self.update)
        self.button.place(x=380, y=300)
        self.label1 = tk.Label(self, text='原始文本', font=('', 10))
        self.label1.place(x=160, y=5)
        self.text1 = tk.Text(width=50, height=40)
        self.text1.place(x=5, y=30)
        self.label2 = tk.Label(self, text='果文本', font=('', 10))
        self.label2.place(x=600, y=5)
        self.text2 = tk.Text(width=50, height=40)
        self.text2.place(x=440, y=30)

    def update(self):
        import tkinter.messagebox
        if len(self.text1.get('0.0', 'end')) == 1:
            tkinter.messagebox.showinfo('提示', '继续')
        else:
            self.text2.delete('1.0', 'end')
            one_content = []
            two_content = []
            three_content = []
            four_content = []
            one_content = self.text1.get('0.0', 'end').split("\n")
            for i in range(len(one_content)):
                if one_content != '':
                    two_content.append(one_content)
                else:
                    pass
            for i in range(len(two_content)):
                if two_content[0] == ':':
                    three_content.append(two_content[1:])
                else:
                    three_content.append(two_content)
            for i in range(len(three_content)):
                if int(len(three_content)) == int(i + 1):
                    four_content.append("'" + three_content.replace(": ", "': '") + "'")
                else:
                    four_content.append("'" + three_content.replace(": ", "': '") + "',")
            for i in range(len(four_content)):
                if int(len(four_content)) == int(i + 1):
                    self.text2.insert('insert', four_content)
                else:
                    self.text2.insert('insert', four_content + '\n')
            self.text2.update()


def main():
    app = MyApp()
    app.mainloop()


if __name__ == '__main__':
    main()

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

vagrantear 发表于 2020-3-30 23:33
深夜学习hhh,感谢分享
thinkingbullet1 发表于 2020-3-30 23:59
daimiaopeng 发表于 2020-3-31 10:22
 楼主| Clinton 发表于 2020-3-31 11:02
daimiaopeng 发表于 2020-3-31 10:22
怎么用?没有转换的按钮

在python3 win环境下都可以的 我试了3.6和3.4
吾更爱你 发表于 2020-3-31 11:21
加引号么 正则就行了啊
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-9-17 04:13

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表