python3爬虫之设计签名小程序
作者:three_co 时间:2021-09-16 00:26:46
本文实例为大家分享了python3设计签名小程序的具体代码,供大家参考,具体内容如下
首先,上一下要做的效果图:
先是这样一个丑陋的界面(我尽力了的真的!)
然后随便输入名字
然后点击按钮会显示出对应的个性签名:
这个是怎么实现的呢?
其实这个是将一个签名网站http://www.uustv.com/的内容爬下来显示了而已:
源代码如下:
from tkinter import *
import requests
from tkinter import messagebox
import re
from PIL import Image,ImageTk
def download():
startUrl = 'http://www.uustv.com/'
name = entry.get()
if not name:
messagebox.showinfo('提示','请输入名字!')
else:
data = {
'word':name,
'sizes':'60',
'fonts':'jfcs.ttf',
'fontcolor':'#000000'
}
result = requests.post(startUrl,data = data)
result.encoding = 'utf-8'
req = '<div class="tu"><img src="(.*?)"/></div>'
imgUrl = startUrl+(re.findall(req,result.text)[0])
response = requests.get(imgUrl).content
with open('{}.gif'.format(name),'wb') as f:
f.write(response)
#im = Image.open('{}.gif'.format(name))
#im.show()
bm = ImageTk.PhotoImage(file = 'E:\py\{}.gif'.format(name))
label2 = Label(root, image = bm)
label2.bm = bm
label2.grid(row = 2,columnspan = 2)
root = Tk()
root.title('GUI')
root.geometry('600x300')
root.geometry('+500+200')
label = Label(root,text = '签名',font = ('华文行楷',20))
label.grid(row=0,column = 0)
entry = Entry(root,font = ('微软雅黑',20))
entry.grid(row = 0,column = 1)
Button(root,text = '设计签名',font = ('微软雅黑',20),command = download).grid(row = 1,column = 0)
root.mainloop()
关于图形界面GUI的操作之前博客已经说过了,主要就是三步:
1、root = Tk()
2、将标签和按钮等组件放进去
3、root.mainloop()
这里用的是requests去请求一个网页,post传入参数网址和data,data是怎么获取的呢?
打开浏览器,输入网址然后右键检查元素,点击网络,刷新页面删掉之前的记录,然后输入名字点击获取签名
然后得到页面如下:
注意右边的参数即是我们需要的data,但是输入的名字一直是变得,其余三个是不会变的。
至于关于tkinter这些组件常用的有哪些,这里找到一篇好的博客供大家参考:tkinter模块常用参数(python3)
来源:https://blog.csdn.net/three_co/article/details/78450983
标签:python,爬虫,签名
0
投稿
猜你喜欢
W3C优质网页小贴士(四)
2008-04-17 13:34:00
阿里巴巴工程师分享MySQL经验
2010-04-22 16:21:00
Python中的变量赋值
2023-07-23 06:00:10
Python的装饰器使用详解
2023-07-26 02:21:17
python通过wxPython打开一个音频文件并播放的方法
2021-10-20 16:15:08
SQL处理多级分类,查询结果呈树形结构
2012-08-21 10:50:12
基于Python中求和函数sum的用法详解
2022-12-05 23:26:18
Python图像分割之均匀性度量法分析
2021-02-11 11:45:24
动态程序防采集的新方法
2010-04-24 15:24:00
详解Python中映射类型(字典)操作符的概念和使用
2021-12-05 09:24:43
python中pygame安装过程(超级详细)
2022-08-05 04:26:15
python产生模拟数据faker库的使用详解
2022-05-25 22:43:35
详解Python命令行解析工具Argparse
2022-12-11 15:49:28
Python多线程编程(二):启动线程的两种方法
2023-11-27 16:15:48
Pytorch搭建SRGAN平台提升图片超分辨率
2022-10-03 14:02:01
10 个Python中Pip的使用技巧分享
2023-08-02 17:52:45
Python 敏感词过滤的实现示例
2021-07-04 12:17:28
Python入门之字符串操作详解
2023-01-27 18:45:08
IE7下动态创建Iframe时,去除边框的办法
2009-01-19 13:56:00
Python实现学生管理系统的代码(JSON模块)
2022-01-02 07:54:42