思路

改進(jìn)原博主文章(Python GUI–Tkinter簡(jiǎn)單實(shí)現(xiàn)個(gè)性簽名設(shè)計(jì))的代碼,原先的代碼是基于Python2的,我這份代碼基于Python3 并針對(duì)當(dāng)前的網(wǎng)站做了相應(yīng)調(diào)整
前置要求
Python 3.X
tkinter
PIL
完整代碼
# -*- coding:utf-8 -*-
from tkinter import *
import tkinter
import requests
import re
from PIL import Image
def download():
start_url = 'http://www.uustv.com/'
name = entry.get().encode('utf-8')
if not name:
return
data = {
'word': name,
'sizes': '60',
'fonts': 'jfcs.ttf', # 個(gè)性簽
# 'fonts': 'qmt.ttf', # 連筆簽
# 'fonts': 'bzcs.ttf', # 瀟灑簽
# 'fonts': 'lfc.ttf', # 草體簽
# 'fonts': 'haku.ttf', # 合文簽
# 'fonts': 'zql.ttf', # 商務(wù)簽
# 'fonts': 'yqk.ttf', # 可愛簽
'fontcolor': '#00FF00'
}
result = requests.post(start_url, data=data).content
# 截止20180302 網(wǎng)站CSS變動(dòng)
reg = '<div class="tu">.*<img src="(.*?)"/></div>'
# byte轉(zhuǎn)string
result = bytes.decode(result)
img_url = start_url+re.findall(reg, result)[0]
# 避免了原代碼在Win下無(wú)法正常寫入文件的問(wèn)題
name = 'tmp'
response = requests.get(img_url).content
with open('{}.gif'.format(name), 'wb') as f:
f.write(response)
try:
im = Image.open('{}.gif'.format(name))
im.show()
except Exception as e:
raise e
root = tkinter.Tk()
root.title('個(gè)性簽名設(shè)計(jì)')
root.geometry('+800+300')
Label(root, text='姓名', font=('微軟雅黑', 15)).grid()
entry = Entry(root, font=('微軟雅黑', 15))
entry.grid(row=0, column=1)
button = Button(root, text='設(shè)計(jì)簽名', font=('微軟雅黑', 15),
width='15', height=1, command=download)
button.grid(row=1, column=1)
root.mainloop()
網(wǎng)頁(yè)標(biāo)題:python如何爬取個(gè)性簽名-創(chuàng)新互聯(lián)
文章網(wǎng)址:http://www.chinadenli.net/article10/pchgo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、面包屑導(dǎo)航、服務(wù)器托管、關(guān)鍵詞優(yōu)化、網(wǎng)站營(yíng)銷
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容
移動(dòng)網(wǎng)站建設(shè)知識(shí)