例如:某个平台的登录验证码
如上图所示:1、 它叫做data URI scheme,是一种网页优化的手段。让我们直接把图像的内容崁入网页里面,减少页面的请求。
2、浏览器并不会缓存这样的图片
3、data URI scheme 虽然节省 HTTP 请求,但是倘若这个图像要在网页多个地方显示的话,便会加大网页的内容,延长了下载的时间
4、其中一个解决办法是在一个 CSS class 中加入 data URL,在需要显示图像的区块调用这个 class
这种src的解析
python 代码实现:src转化为图片
import base64 src = "data:image/gif;base64,R0lGODlheQAoAIcAAAAAAAAARAAAiAAAzABEAABERABEiABEzACIAACIRACIiACIzADMAADMRADMiADMzADd3REREQAAVQAAmQAA3QBVAABVVQBMmQBJ3QCZAACZTACZmQCT3QDdAADdSQDdkwDungDu7iIiIgAAZgAAqgAA7gBmAABmZgBVqgBP7gCqAACqVQCqqgCe7gDuAADuTwD/VQD/qgD//zMzMwAAdwAAuwAA/wB3AAB3dwBduwBV/wC7AAC7XQC7uwCq/wD/AEQAREQAiEQAzEREAEREREREiEREzESIAESIRESIiESIzETMAETMRETMiETMzEQAAFUAAFUAVUwAmUkA3VVVAFVVVUxMmUlJ3UyZAEyZTEyZmUmT3UndAEndSUndk0nd3U/u7mYAAGYAZlUAqk8A7mZmAGZmZlVVqk9P7lWqAFWqVVWqqk+e7k/uAE/uT0/unlX/qlX//3cAAHcAd10Au1UA/3d3AHd3d11du1VV/127AF27XV27u1Wq/1X/AFX/VYgAiIgAzIhEAIhERIhEiIhEzIiIAIiIRIiIiIiIzIjMAIjMRIjMiIjMzIgAAIgARJkATJkAmZMA3ZlMAJlMTJlMmZNJ3ZmZAJmZTJmZmZOT3ZPdAJPdSZPdk5Pd3ZkAAKoAAKoAVaoAqp4A7qpVAKpVVapVqp5P7qqqAKqqVaqqqp6e7p7uAJ7uT57unp7u7qr//7sAALsAXbsAu6oA/7tdALtdXbtdu6pV/7u7ALu7Xbu7u6qq/6r/AKr/Var/qswAzMxEAMxERMxEiMxEzMyIAMyIRMyIiMyIzMzMAMzMRMzMiMzMzMwAAMw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ldevFOaQUe67v3NFpz4zD7zQjLbpDM87aCM0pMqJQmmm1BmXkWeq+hizb6aKSTVtrBpYfOCSGQ1DNI6qSpFmgljmbKSyGbke56RZl2spokicZuuiGzr9Pr7JO+TuumgAAAOw==" data = src.split(\',\')[1] image_data = base64.b64decode(data) with open(\'1.gif\', \'wb\') as f: f.write(image_data)