111升学论坛

 找回密码
 加入家园
专业、学校怎么选?免费公益咨询解答开通学校版块微信:543646没考上高中怎么办,不要慌!
热门:大连报关学校招生网增加印象分,实用新型专利包过申请发明专利申请并不难,代写全部材料,轻松申请!
查看: 408|回复: 0

Python开发个人专属表情包网站,表情在手,天下我有

[复制链接]

42

主题

17

回帖

153

积分

新手上路

Rank: 1

积分
153
发表于 2021-2-22 21:32:21 | 显示全部楼层 |阅读模式
集群智慧云科服发明专利申请



“表情包”是一种利用图片来表示感情的一种方式。表情包是在社交软件活跃之后,形成的一种流行文化,表情包流行于互联网上面,基本人人都会发表情。
曾经你是否也有过找不到表情包去应对别人的时候。
今天小编分享如何用Python开发个人专属的表情包网站,想用什么表情包搜一下就有了!



本篇分为两部分
1、爬取表情包存入数据库
2、搭建个人个人专属表情网站
爬取包情包存入数据库
环境:Windows+Python3.6
IDE:个人喜好
模块
import requestsimport reimport pymysq完整代码
import requestsimport reimport pymysql# 连接数据库db = pymysql.connect(host = '127.0.0.1',port = 3306,db = 'db',user = 'root',passwd = 'root',charset = 'utf8')# 创建游标cursor = db.cursor()# cursor.execute('select * from images')# print(cursor.fetchall())# 小驼峰# 注释 获取图片列表def getImagesList(page):  # 获取斗图网源代码  html = requests.get('http://www.doutula.com/photo/list/?page={}'.format(page)).text  # 正则表达式 通配符 .*? 匹配所有  分组匹配  reg = r'data-original="(.*?)".*?alt="(.*?)"'  # 增加匹配效率的 S 多行匹配  reg = re.compile(reg,re.S)  imagesList = re.findall(reg,html)  for i in imagesList:    image_url = i[0]    image_title = i[1]    # format 字符串格式化 %s    cursor.execute("insert into images(`name`,`imageUrl`) values('{}','{}') ".format(image_title,image_url))    print('正在保存 %s'%image_title)    db.commit()# range 范围   1<=X<1000for i in range(1,1001):  print('第{}页'.format(i))  getImagesList(i)效果图



网站开发
使用的框架是Flask
from flask import Flaskfrom flask import render_templatefrom flask import requestimport pymysql# 404 页面未找到app = Flask(__name__)# 装饰器@app.route('/') # route 路由def index():  # return "hello world"  return render_template('index.html')@app.route('/search')def search():  # 接收用户关键字  keyword = request.args.get('kw')  count = request.args.get('count')  cursor.execute("select * from images where name like '%{}%'".format(keyword))  data = cursor.fetchmany(int(count))  return render_template('index.html',images = data)# 程序的入口if __name__ == '__main__':  db = pymysql.connect(host='127.0.0.1', port=3306, db='db', user='root', passwd='root', charset='utf8',cursorclass = pymysql.cursors.DictCursor)  # 创建游标  cursor = db.cursor()  # 调试模式  # port 端口号 默认5000  app.run(debug=True,port=8000)运行效果图



小编这里有一份Python学习的全套视频教程,现在拿出来免费分享给大家!








转发此文,关注并私信小编关键字“资料”即可免费获取
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入家园

本版积分规则

QQ|Archiver|手机版|小黑屋|111升学论坛

GMT+8, 2024-9-20 05:58

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表