Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想从网页中抓取图像,问题是图像作为数据 URI 包含在源代码中。如何将它们保存到文件中?(我只需要从特定的抓取数据 URI 代码访问 URI 图像)
图像/字符串采用 base64 编码(甚至在 URI 本身中也有说明!)。您所要做的就是对其进行解码,然后将其写入文件。
imageContents = "/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxQSEhUUE" myfile = open("image.jpg","w") myfile.write(imageContents.decode("base64")) myfile.close()