python如何爬取个性签名

yipeiwu_com5年前Python爬虫

思路

改进原博主文章(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设计】。

相关文章

Python3直接爬取图片URL并保存示例

有时候我们会需要从网络上爬取一些图片,来满足我们形形色色直至不可描述的需求。 一个典型的简单爬虫项目步骤包括两步:获取网页地址和提取保存数据。 这里是一个简单的从图片url收集图片的例子...

python抓取京东小米8手机配置信息

python抓取京东小米8手机配置信息

本文代码是使用python抓取京东小米8手机的配置信息 首先找到小米8商品的链接:https://item.jd.com/7437788.html 然后找到其配置信息的标签,我们找到其配...

Python 爬虫实现增加播客访问量的方法实现

一、序言: 世界 1024 程序猿节日不加班,闲着没事儿。。。随手写了个播客访问量爬虫玩玩,访问量过万不是事儿!!!每个步骤注释都很清晰,代码仅供学习参考! ---- Nick.Pen...

python制作最美应用的爬虫

安卓最美应用页面爬虫,爬虫很简单,设计的东西到挺多的 文件操作 正则表达式 字符串替换等等 import requests import re url = "http://zuime...

Python实现的爬取小说爬虫功能示例

本文实例讲述了Python实现的爬取小说爬虫功能。分享给大家供大家参考,具体如下: 想把顶点小说网上的一篇持续更新的小说下下来,就写了一个简单的爬虫,可以爬取爬取各个章节的内容,保存到t...