99V久久综合狠狠综合久久|久久se无码精品一区二区|99国产精美欧美一区二区|久久99国产精品亚洲

Python開發(fā)個人專屬表情包網(wǎng)站,表情在手,天下我有!

2020-11-19 13:02:47  閱讀:-  來源:
Python開發(fā)個人專屬表情包網(wǎng)站,表情在手,天下我有

“表情包”是一種利用圖片來表示感情的一種方式。表情包是在社交軟件活躍之后,形成的一種流行文化,表情包流行于互聯(lián)網(wǎng)上面,基本人人都會發(fā)表情。

曾經(jīng)你是否也有過找不到表情包去應(yīng)對別人的時候。

今天小編分享如何用Python開發(fā)個人專屬的表情包網(wǎng)站,想用什么表情包搜一下就有了!

Python開發(fā)個人專屬表情包網(wǎng)站,表情在手,天下我有

本篇分為兩部分

1、爬取表情包存入數(shù)據(jù)庫

2、搭建個人個人專屬表情網(wǎng)站

爬取包情包存入數(shù)據(jù)庫

環(huán)境:Windows+Python3.6

IDE:個人喜好

模塊

import requestsimport reimport pymysq

完整代碼

import requestsimport reimport pymysql# 連接數(shù)據(jù)庫db = pymysql.connect(host = '127.0.0.1',port = 3306,db = 'db',user = 'root',passwd = 'root',charset = 'utf8')# 創(chuàng)建游標(biāo)cursor = db.cursor()# cursor.execute('select * from images')# print(cursor.fetchall())# 小駝峰# 注釋 獲取圖片列表def getImagesList(page):  # 獲取斗圖網(wǎng)源代碼  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)

效果圖

Python開發(fā)個人專屬表情包網(wǎng)站,表情在手,天下我有

網(wǎng)站開發(fā)

使用的框架是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():  # 接收用戶關(guān)鍵字  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)  # 創(chuàng)建游標(biāo)  cursor = db.cursor()  # 調(diào)試模式  # port 端口號 默認(rèn)5000  app.run(debug=True,port=8000)

運行效果圖

Python開發(fā)個人專屬表情包網(wǎng)站,表情在手,天下我有

小編這里有一份Python學(xué)習(xí)的全套視頻教程,現(xiàn)在拿出來免費分享給大家!

Python開發(fā)個人專屬表情包網(wǎng)站,表情在手,天下我有


Python開發(fā)個人專屬表情包網(wǎng)站,表情在手,天下我有

轉(zhuǎn)發(fā)此文,關(guān)注并私信小編關(guān)鍵字“資料”即可免費獲取

怀集县| 镇赉县| 攀枝花市| 龙川县| 铅山县| 正镶白旗| 和田市| 黔南| 诸暨市| 宽城| 瑞安市| 明水县| 濉溪县| 普洱| 浦江县| 博客| 呼图壁县| 苏尼特左旗| 班戈县| 河东区| 赤水市| 定边县| 鄂伦春自治旗| 桓仁| 彭阳县| 平泉县| 涿鹿县| 五大连池市| 灵山县| 三原县| 隆回县| 宁远县| 塔河县| 安陆市| 罗平县| 云和县| 汕尾市| 永登县| 花莲县| 平罗县| 南丹县|