python如何爬取个性签名


Posted in Python onJune 19, 2018

思路

改进原博主文章(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()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
tornado捕获和处理404错误的方法
Feb 26 Python
Ubuntu 16.04 LTS中源码安装Python 3.6.0的方法教程
Dec 27 Python
python实时获取外部程序输出结果的方法
Jan 12 Python
聊聊python里如何用Borg pattern实现的单例模式
Jun 06 Python
python中pytest收集用例规则与运行指定用例详解
Jun 27 Python
pybind11和numpy进行交互的方法
Jul 04 Python
详解Python3中的 input() 函数
Mar 18 Python
Python tornado上传文件的功能
Mar 26 Python
python读取配置文件方式(ini、yaml、xml)
Apr 09 Python
200行python代码实现贪吃蛇游戏
Apr 24 Python
scrapy头部修改的方法详解
Dec 06 Python
基于python实现银行管理系统
Apr 20 Python
详解TensorFlow查看ckpt中变量的几种方法
Jun 19 #Python
TensorFlow 滑动平均的示例代码
Jun 19 #Python
python3个性签名设计实现代码
Jun 19 #Python
TensorFlow 模型载入方法汇总(小结)
Jun 19 #Python
python3爬虫之设计签名小程序
Jun 19 #Python
Python GUI Tkinter简单实现个性签名设计
Jun 19 #Python
TensorFlow数据输入的方法示例
Jun 19 #Python
You might like
php中使用preg_match_all匹配文章中的图片
2013/02/06 PHP
基于xcache的配置与使用详解
2013/06/18 PHP
微信营销平台系统?刮刮乐的开发
2014/06/10 PHP
PHP性能分析工具XHProf安装使用教程
2015/05/13 PHP
Zend Framework教程之请求对象的封装Zend_Controller_Request实例详解
2016/03/07 PHP
PHP对称加密函数实现数据的加密解密
2016/10/27 PHP
php实现查询功能(数据访问)
2017/05/23 PHP
实例讲解php将字符串输出到HTML
2019/01/27 PHP
thinkPHP5框架实现多数据库连接,跨数据连接查询操作示例
2019/05/29 PHP
Laravel实现搜索的时候分页并携带参数
2019/10/15 PHP
PHP如何使用JWT做Api接口身份认证的实现
2020/02/03 PHP
JS小功能(操作Table--动态添加删除表格及数据)实现代码
2013/11/28 Javascript
jQuery 获取兄弟元素的几种不错方法
2014/05/23 Javascript
jQuery实现流动虚线框的方法
2015/01/29 Javascript
vue proxyTable 接口跨域请求调试的示例
2017/09/12 Javascript
详解在WebStorm中添加Vue.js单文件组件的高亮及语法支持
2017/10/21 Javascript
angular2系列之路由转场动画的示例代码
2017/11/09 Javascript
node.js实现为PDF添加水印的示例代码
2018/12/05 Javascript
Vue项目中如何使用Axios封装http请求详解
2019/10/23 Javascript
JS实现滑动导航效果
2020/01/14 Javascript
[16:19]教你分分钟做大人——风暴之灵
2015/03/11 DOTA
[00:35]TI7不朽珍藏III——寒冰飞龙不朽展示
2017/07/15 DOTA
使用sklearn之LabelEncoder将Label标准化的方法
2018/07/11 Python
python+mysql实现个人论文管理系统
2019/10/25 Python
日本快乐生活方式购物网站:Shop Japan
2018/07/17 全球购物
Herschel Supply Co.美国:背包、手提袋及配件
2020/11/24 全球购物
C#面试问题
2016/07/29 面试题
大专学生推荐信范文
2013/11/19 职场文书
个人自我评价范文
2014/02/05 职场文书
消防工作实施方案
2014/06/09 职场文书
银行会计主管岗位职责
2014/10/01 职场文书
钢铁是怎样炼成的读书笔记
2015/06/29 职场文书
拿破仑传读书笔记
2015/07/01 职场文书
新郎父母婚礼答谢词
2015/09/29 职场文书
python 实现体质指数BMI计算
2021/05/26 Python
MySQL 中如何归档数据的实现方法
2022/03/16 SQL Server