欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python3爬蟲之設(shè)計簽名小程序

 更新時間:2018年06月19日 09:13:10   作者:three_co  
這篇文章主要為大家詳細介紹了python3爬蟲之寫為朋友設(shè)計簽名的小程序,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了python3設(shè)計簽名小程序的具體代碼,供大家參考,具體內(nèi)容如下

首先,上一下要做的效果圖:

先是這樣一個丑陋的界面(我盡力了的真的?。?/p>

然后隨便輸入名字

然后點擊按鈕會顯示出對應(yīng)的個性簽名:

這個是怎么實現(xiàn)的呢?

其實這個是將一個簽名網(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('提示','請輸入名字!') 
  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è)計簽名',font = ('微軟雅黑',20),command = download).grid(row = 1,column = 0) 
 
root.mainloop() 

關(guān)于圖形界面GUI的操作之前博客已經(jīng)說過了,主要就是三步:

1、root = Tk()

2、將標(biāo)簽和按鈕等組件放進去

3、root.mainloop()

這里用的是requests去請求一個網(wǎng)頁,post傳入?yún)?shù)網(wǎng)址和data,data是怎么獲取的呢?

打開瀏覽器,輸入網(wǎng)址然后右鍵檢查元素,點擊網(wǎng)絡(luò),刷新頁面刪掉之前的記錄,然后輸入名字點擊獲取簽名

然后得到頁面如下:

注意右邊的參數(shù)即是我們需要的data,但是輸入的名字一直是變得,其余三個是不會變的。

至于關(guān)于tkinter這些組件常用的有哪些,這里找到一篇好的博客供大家參考:tkinter模塊常用參數(shù)(python3)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論