python3爬蟲之設(shè)計(jì)簽名小程序
本文實(shí)例為大家分享了python3設(shè)計(jì)簽名小程序的具體代碼,供大家參考,具體內(nèi)容如下
首先,上一下要做的效果圖:
先是這樣一個(gè)丑陋的界面(我盡力了的真的!)

然后隨便輸入名字

然后點(diǎn)擊按鈕會(huì)顯示出對(duì)應(yīng)的個(gè)性簽名:

這個(gè)是怎么實(shí)現(xiàn)的呢?
其實(shí)這個(gè)是將一個(gè)簽名網(wǎng)站http://www.uustv.com/的內(nèi)容爬下來顯示了而已:
源代碼如下:
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('提示','請(qǐng)輸入名字!')
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 = '設(shè)計(jì)簽名',font = ('微軟雅黑',20),command = download).grid(row = 1,column = 0)
root.mainloop()
關(guān)于圖形界面GUI的操作之前博客已經(jīng)說過了,主要就是三步:
1、root = Tk()
2、將標(biāo)簽和按鈕等組件放進(jìn)去
3、root.mainloop()
這里用的是requests去請(qǐng)求一個(gè)網(wǎng)頁,post傳入?yún)?shù)網(wǎng)址和data,data是怎么獲取的呢?
打開瀏覽器,輸入網(wǎng)址然后右鍵檢查元素,點(diǎn)擊網(wǎng)絡(luò),刷新頁面刪掉之前的記錄,然后輸入名字點(diǎn)擊獲取簽名
然后得到頁面如下:

注意右邊的參數(shù)即是我們需要的data,但是輸入的名字一直是變得,其余三個(gè)是不會(huì)變的。
至于關(guān)于tkinter這些組件常用的有哪些,這里找到一篇好的博客供大家參考:tkinter模塊常用參數(shù)(python3)
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python3爬蟲爬取英雄聯(lián)盟高清桌面壁紙功能示例【基于Scrapy框架】
- Python3爬蟲爬取百姓網(wǎng)列表并保存為json功能示例【基于request、lxml和json模塊】
- Python3實(shí)現(xiàn)爬蟲爬取趕集網(wǎng)列表功能【基于request和BeautifulSoup模塊】
- python3第三方爬蟲庫BeautifulSoup4安裝教程
- Python3多線程爬蟲實(shí)例講解代碼
- python3簡單實(shí)現(xiàn)微信爬蟲
- python3爬蟲之入門基礎(chǔ)和正則表達(dá)式
- python3制作捧腹網(wǎng)段子頁爬蟲
- Python3爬蟲學(xué)習(xí)入門教程
相關(guān)文章
Python計(jì)算時(shí)間間隔(精確到微妙)的代碼實(shí)例
今天小編就為大家分享一篇關(guān)于Python計(jì)算時(shí)間間隔(精確到微妙)的代碼實(shí)例,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-02-02
Python中json格式數(shù)據(jù)的編碼與解碼方法詳解
這篇文章主要介紹了Python中json格式數(shù)據(jù)的編碼與解碼方法,詳細(xì)分析了Python針對(duì)json格式數(shù)據(jù)的編碼轉(zhuǎn)換操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07
python自然語言處理之字典樹知識(shí)總結(jié)
這篇文章主要介紹了python自然語言處理之字典樹知識(shí)總結(jié),文中有非常詳細(xì)的代碼示例,對(duì)正在學(xué)習(xí)python的小伙伴們有非常好的幫助,需要的朋友可以參考下2021-04-04

