135-1821-9792

python如何爬取个性签名-创新互联

思路

创新互联建站-专业网站定制、快速模板网站建设、高性价比雨城网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式雨城网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖雨城地区。费用合理售后完善,10余年实体公司更值得信赖。

改进原博主文章(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 = '
.*
' # 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()

本文题目:python如何爬取个性签名-创新互联
文章起源:http://kswsj.com/article/pchgo.html

其他资讯



Copyright © 2009-2022 www.kswsj.com 成都快上网科技有限公司 版权所有 蜀ICP备19037934号