当前位置: 移动技术网 > IT编程>脚本编程>Python > python如何爬取个性签名

python如何爬取个性签名

2018年08月19日  | 移动技术网IT编程  | 我要评论

路人江美琪,橘优花,阿忠农家乐

思路

改进原博主文章(python gui–tkinter简单实现个性签名设计)的代码,原先的代码是基于python2的,我这份代码基于python3 并针对当前的网站做了相应调整

前置要求

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', # 个性签
    # 'fonts': 'qmt.ttf', # 连笔签
    # 'fonts': 'bzcs.ttf', # 潇洒签
    # 'fonts': 'lfc.ttf', # 草体签
    # 'fonts': 'haku.ttf', # 合文签
    # 'fonts': 'zql.ttf', # 商务签
    # 'fonts': 'yqk.ttf', # 可爱签
    'fontcolor': '#00ff00'
  }
  result = requests.post(start_url, data=data).content
  # 截止20180302 网站css变动
  reg = '<div class="tu">.*<img src="(.*?)"/></div>'
  # byte转string
  result = bytes.decode(result)
  img_url = start_url+re.findall(reg, result)[0]
  # 避免了原代码在win下无法正常写入文件的问题
  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('个性签名设计')
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='设计签名', font=('微软雅黑', 15),
        width='15', height=1, command=download)
button.grid(row=1, column=1)
root.mainloop()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网