大家好,欢迎来到IT知识分享网。
“表情包”是一种利用图片来表示感情的一种方式。表情包是在社交软件活跃之后,形成的一种流行文化,表情包流行于互联网上面,基本人人都会发表情。
曾经你是否也有过找不到表情包去应对别人的时候。
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(): # 接收用户关键字 keywod = request.args.get('kw') count = request.args.get('count') cursor.execute("select * from images where name like '%{}%'".format(keywod)) 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='rot', paswd='rot', charset='utf8',cursorclass = pymysql.cursors.DictCursor) # 创建游标 cursor = db.cursor() # 调试模式 # port 端口号 默认5000 app.run(debug=True,port=8000)
运行效果图
这里给大家分享一份Python全套学习资料,包括学习路线、软件、源码、视频、面试题等等,都是我自己学习时整理的,希望可以对正在学习或者想要学习Python的朋友有帮助!
CSDN大礼包:全网最全《全套Python学习资料》免费分享🎁
😝有需要的小伙伴,可以点击下方链接免费领取或者V扫描下方二维码免费领取🆓
👉CSDN大礼包🎁:全网最全《Python学习资料》免费分享(安全链接,放心点击)👈
1️⃣零基础入门
① 学习路线
对于从来没有接触过Python的同学,我们帮你准备了详细的学习成长路线图。可以说是最科学最系统的学习路线,你可以按照上面的知识点去找对应的学习资源,保证自己学得较为全面。
② 路线对应学习视频
还有很多适合0基础入门的学习视频,有了这些视频,轻轻松松上手Python~
③练习题
2️⃣国内外Python书籍、文档
① 文档和书籍资料
3️⃣Python工具包+项目源码合集
①Python工具包
②Python实战案例
③Python小游戏源码
4️⃣Python面试题
5️⃣Python兼职渠道
👉CSDN大礼包🎁:全网最全《Python学习资料》免费分享(安全链接,放心点击)👈
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/120136.html





