当前位置: 首页 > 工具软件 > src2png > 使用案例 >

网页中遇到的src="data:image/png;base64,xxxx"知识点了解

昌栋
2023-12-01

    在学爬虫中,总是习惯去找网上图片的url,但是你一定会遇到我题目说说的问题。网页上有些图片的src或css背景图片的url后面跟了一大串字符,比如:

data:image/png;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCADJAMgDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD2+3vkkjDE05ro+ZhFyvrVG3tnWPORmrf+rUDHNcMK07JyViCC4mMrEAVEow+WOBU8lu6L5i/Wq0w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+lbsfWx/wCA/wA6reLf+Pv/AIEf5CnjYL2Z00MZKGI5ElZnHWp2sqt/umrenItrqJbPDdRVOP8A13/A6uJ/x9ivGpTcaiserW1pM6SB8scfoKn1HR5/s6TPEfkIbI/h+vpUFn/rV/3/APCuv1X/AJBt3/uCvRqvmlyvbQ+cpUeWisTF2ldo8q1OBEuXMOCFIzj361cjEkCK4yydmx/Oqt7/AK25/wB4VpH/AJBI+lee4Jt+R7sKkowi097fkbFhqpeIR9Qozn2q0Gu7/wCRI3UE4U+vvXP6f/q3/wCuZrstF/5dvo3867KUV7Dn6nPjk6k4wvZPscje2z21/NFIgyV2H2rAa0SC9UTL+7cc11viH/kNXP8Av1zeqf66L6mir8LZ5uCk1XVHoVtV0C4stKF/DKrRA58sjpWK/RXHcV3mu/8AIlyfWuD/AOXeP6D+lck4qOx9EtVzEgbBDnpnmknXEyhehHBpD/qf8+tSS9Yvp/Ss7lcq5rk1mw3IfwrufD1xFHcNvYiORNw43EMK4Sz+8n+9XW6L9+H/AHW/pSjuTOKe51A1+KLzbA2oDLlldu9OgvFgkRfmdZRluOFHtXPXv/IcP+5/SthfuQ/9cx/OvVjFchyylyuyW5ffTpp7kACJ4mG5ZT6Ht9a2dM0HToT5xgV5f7zdqhs/+PSD/dH862LP7p+teBi6knOydtDPD0o8rv3LSqI0CoQAOmKKb3/GivKk3fc7OVH/2Q==
        那么这是什么呢?这是Data URI scheme。
        Data URI scheme是在RFC2397中定义的,目的是将一些小的数据,直接嵌入到网页中,从而不用再从外部文件载入。比如上面那串字符,其实是一张小图片,将这些字符复制黏贴到浏览器的地址栏中并转到,就能看到它了,也就是我的头像。^_^
在上面的Data URI中,data表示取得数据的协定名称,image/png 是数据类型名称,base64 是数据的编码方法,
        逗号后面就是这个image/png文件base64编码后的数据。

        目前,Data URI scheme支持的类型有:

data:,文本数据
data:text/plain,文本数据
data:text/html,HTML代码
data:text/html;base64,base64编码的HTML代码
data:text/css,CSS代码
data:text/css;base64,base64编码的CSS代码
data:text/javascript,Javascript代码
data:text/javascript;base64,base64编码的Javascript代码
data:image/gif;base64,base64编码的gif图片数据
data:image/png;base64,base64编码的png图片数据
data:image/jpeg;base64,base64编码的jpeg图片数据

data:image/x-icon;base64,base64编码的icon图片数据

    base64简单地说,它把一些 8-bit 数据翻译成标准 ASCII 字符,网上有很多免费的base64 编码和解码的工具,在目前,IE8、Firfox、Chrome、Opera浏览器都支持这种小文件嵌入。

关于base64编码如下:

    测试例子,把文字转成base64编码

>>> import base64
>>> ls_s='字符串文本'
>>> ls_t=base64.b64encode(ls_s) #转换文本内容到base64
>>> print ls_t
19a3+7SuzsSxvg==
>>> print base64.b64decode(ls_t) #解码
字符串文本
>>>
# 把图片内容转成base64编码
import base64
f=open(r'x:\1.jpg','rb') #二进制方式打开图文件
ls_f=base64.b64encode(f.read()) #读取文件内容,转换为base64编码 
f.close()

把编码文本写入一个txt文件
fw=open(r'x:\1.txt','w') #打开一个空白文本文件,准备写入
fw.write(ls_f)
fw.flush()
fw.close()
网页的表达
<html><body><img src="https://img-blog.csdnimg.cn/2022010614494780744.jpeg" /></body></html>
*注意 image/jpeg 如果图片是其它类型的,这里也要修改; image/png、image/gif、image/bmp 等
data: URI定义于IETF标准的RFC 2397 
data: URI的基本使用格式如下: 

data:[<MIME-type>][;base64|charset=some_charset],<data> 

借鉴他人整理分享

 类似资料: