Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to develop a personal meme website by Python

Shulou Source: shulou.com Published: 2022-06-01 19:55:35 10月30日 Update

This article mainly introduces "how to develop a personal meme website by Python". In daily operation, I believe that many people have doubts about how to develop a personal meme website by Python. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to develop a personal meme website by Python". Next, please follow the editor to study!

Crawl memes and store them in the database

Environment: Windows+Python3.6

IDE: personal preference

Module

Import requestsimport reimport pymysq

Complete code

Import requestsimport reimport pymysql# connects to the database db = pymysql.connect (host = '127.0.0.1) database db =' db',user = 'root',passwd =' root' Charset = 'utf8') # create cursor cursor = db.cursor () # cursor.execute (' select * from images') # print (cursor.fetchall ()) # Little Hump # comment get picture list def getImagesList (page): # get Doutu source code html = requests.get ('http://www.doutula.com/photo/list/?page={}'.format(page)).text # regular expression wildcard. *? Match all groups match reg = (. *?) ". *? alt=" (. *?) "'# S multi-line matching reg = re.compile (reg,re.S) imagesList = re.findall (reg) Html) for i in imagesList: image_url = I [0] image_title = I [1] # format string format% s cursor.execute ("insert into images (`name`, `imageUrl`) values ('{}','{}')" .format (image_title,image_url)) print ('saving% s'%image_title) db.commit () # range range 1

Tags: Website personal emoji development learning data database more cursor help utility next code entry key keyword slogan character string effect Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei NVidia vpn Shulou Tech Info MySQL