Preface
Whether you are a college student, a white-collar person who has entered the society, or a famous boss in the business world, you will always ask for signature from time to time. Are you still embarrassed by your ugly signature? No need from now on, because with this article, there is an artist's autograph specially designed for you, which can make you free and easy in social and business negotiations. Come and have a look!
Python crawler collects website data and makes a small signature design software.
First let's go to the target address:
You can see that there is a name input box, a drop-down box for font selection, and a design button.
In fact, if you have any experience, you can guess that this is a typical post submission data, of course, it may also be an API. Now let's see what happens to the design page of the input content point
Conclusion: the website address has not changed. In this case, we can't find the image address in the website source code, even if we can find it
Why can't you do this? It's obvious that if you do this, you will always get a signature design with the same name. Because you don't have a place to submit data (name, font of name).
So let's grab the bag:
As expected, it's a post request. Several parameters need to be submitted. These parameters are not encrypted, so we can directly simulate the request to get the source code and extract the signature image after getting the source code.
Of course, since it is a small software design, I use tkinter module to design software GUI
import requests
from tkinter import *
import re
from tkinter import messagebox
from tkinter import ttk
from PIL import ImageTk
from urllib.request import urlretrieve
path = 'autograph.gif'
def get_image():
# To blank
name = e1.get()
name = name.strip()
print(comboxlist.get())
if name == '':
messagebox.showerror(title='Tips:', message='Please enter a name')
else:
data = {
'word': name,
'sizes': '60',
'fonts': comboxlist.get(),
'fontcolor': '#000000'
}
url = 'http://www.uustv.com/'
req = requests.post(url, data=data)
req.encoding = req.apparent_encoding
response = req.text
reg = re.compile('<div class="tu"><img src="(.*?)"/></div>')
res = re.findall(reg, response)
result = url + res[0]
print(result)
urlretrieve(result, path)
# Picture on window
bm = ImageTk.PhotoImage(file=path)
label2 = Label(root, image=bm)
label2.bm = bm
label2.grid(row=2, columnspan=2)
# create a window
root = Tk()
# Title
root.title('Python Learning group: 595948765')
# Window size, width and height
root.geometry('600x310+500+200')
# Window initial position
# root.geometry('-500+200')
# Label control
l1 = Label(root, text='autograph', font=('Chinese Xingkai', 20), fg='blue')
l1.grid(row=0, column=0)
e1 = Entry(root, width=25, font=('Microsoft YaHei ', 20))
e1.grid(row=0, column=1)
# Click the button
button = Button(root, text='Design signature', font=('Microsoft YaHei ', 22)
, command=get_image)
button.grid(row=1, column=0)
# textvariable=var
comboxlist = ttk.Combobox(root, font=('Microsoft YaHei ', 20), width=2)
comboxlist["values"] = ("jfcs.ttf", "bzcs.ttf", "qmt.ttf",
"lfc.ttf", "haku.ttf", "zql.ttf", "yqk.ttf")
comboxlist.grid(row=0, column=2)
comboxlist.current(0) # Select first
root.mainloop()