data:image/jpg; convert base64 format data into pictures

When crawling pictures with crawlers, I found that some picture urls start with "data:image/jpg;base64". For example, after
insert image description here
obtaining the url in the picture below, you need to base64 decrypt the url, and the decrypted data can be written Picture, see the code below for details

img_imf = img_imf.replace('data:image/jpg;base64,','')

#将data:image/jpg;base64格式的数据转化为图片
page_content = base64.b64decode(img_imf)
file_path = './code.jpg'
with open(file_path, 'wb') as f:
	f.write(page_content)

Guess you like

Origin blog.csdn.net/zhuan_long/article/details/126143998