英文:
how to download an html img when the src is in a strange format (blob)
问题
当我检查元素时,图像的src显示如下(非常长,我不得不大大缩短它才能适应问题):
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAMgCAYAAADbcAZoAAAAAXNSR0IArs4c6QAAIABJREFUeF7svQmUXdV5JvrvfYY7lapKKg2AQJgZNCAkgQbEIEBmMIbEsXFixzExnc7QeXa8eqW7814n8bO7051e6e7V/VavbqftxDZgwxLYQHA6wbETOzZ2bId4AIMNNphZEppquHXvmfZ+6/v32feeKgmjWVWq/ywut3TvGfb59rn77O98//f/imQRBAQBQUAQEAQEAUFAEBAEBIFZg8DDDz+8dOvWrZFS9SBJElWr1VSSJLZWI9PtWks1dyqW/yOqu3drrS2azebLJ/pE1YlugBxfEBAEBAFBQBAQBAQBQUAQEAQOHoEdO3acf4OVbnvxwdtqUobImcZ5IqI1jWy+DMjVEK73FpjGwj8Dc++6cqfI1c6AR/t0Ddbd3heRXkBCjodzf47z8fuv3Cpab2U6BAAnAQwcOjuZVmQt/xU3B1iO3SyKNf57UQ70wN0JDd8B+BP2K7E/LvKIxKU8l9Rrxe7BF9GrRKK7N4cMm6865AwCwFDqHJmBY/JpYV+ZL1VRXa4M8Er70gOBvGOr7wgsbtGyLst0FC4/SHk7r26zSdQVErbt7nc4dmTljuhxzzDEya9ZMmTJ9ugwDgoL+GcqR9Vq4jkCcwe+tgtPQWuK4LCFYepVW4A9wBUoAxG7afffdd0x7e+cnamqqL1m06KgozdgAEIJVM5bFgFNrZkeg2jHa1NSOSmWVZVe279heACCuG04Q6013OBm2h0bGmKBihZrW7FlzpKO9Q9U4UK3CqHz9G/8ol192ucSTKVm2fLlMmz7dFDtQ6/DAnwwIxjLHOY2oI2U6Oaoq3qhoLI45AIyy6pxrgyGTYRNaD7t10zZ5/LHHtH/in/7pH6V/AHYlo2VMHZ2dsqd1jxpT07Mf0YwSPy3wslkoGGNKyDgur+bmFs34XHbZ5dLSMkU+/vFPqBoXRp5yL5wK7JI6wArmi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RY5iSiRletmWtXCVFQUB
<details>
<summary>英文:</summary>
When I inspect element, this is the src shown for the img (extremely long - I had to shorten it a lot for it to fit in the question)
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAyAAAAMgCAYAAADbcAZoAAAAAXNSR0IArs4c6QAAIABJREFUeF7svQmUXdV5JvrvfYY7lapKKg2AQJgZNCAkgQbEIEBmMIbEsXFixzExnc7QeXa8eqW7814n8bO7051e6e7V/VavbqftxDZgwxLYQHA6wbETOzZ2bId4AIMNNphZEppquHXvmfZ+6/v32feeKgmjWVWq/ywut3TvGfb59rn77O98//f/imQRBAQBQUAQEAQEAUFAEBAEBIFZg8DDDz+8dOvWrZFS9SBJElWr1VSSJLZWI9PtWks1dyqW/yOqu3drrS2azebLJ/pE1YlugBxfEBAEBAFBQBAQBAQBQUAQEAQOHoEdO3acf4OVbnvxwdtqUobImcZ5IqI1jWy+DMjVEK73FpjGwj8Dc++6cqfI1c6AR/t0Ddbd3heRXkBCjodzf47z8fuv3Cpab2U6BAAnAQwcOjuZVmQt/xU3B1iO3SyKNf57UQ70wN0JDd8B+BP2K7E/LvKIxKU8l9Rrxe7BF9GrRKK7N4cMm6865AwCwFDqHJmBY/JpYV+ZL1VRXa4M8Er70gOBvGOr7wgsbtGyLst0FC4/SHk7r26zSdQVErbt7nc4dmTljuhxzzDEya9ZMmTJ9ugwDgoL+GcqR9Vq4jkCcwe+tgtPQWuK4LCFYepVW4A9wBUoAxG7afffdd0x7e+cnamqqL1m06KgozdgAEIJVM5bFgFNrZkeg2jHa1NSOSmWVZVe279heACCuG04Q6013OBm2h0bGmKBihZrW7FlzpKO9Q9U4UK3CqHz9G/8ol192ucSTKVm2fLlMmz7dFDtQ6/DAnwwIxjLHOY2oI2U6Oaoq3qhoLI45AIyy6pxrgyGTYRNaD7t10zZ5/LHHtH/in/7pH6V/AHYlo2VMHZ2dsqd1jxpT07Mf0YwSPy3wslkoGGNKyDgur+bmFs34XHbZ5dLSMkU+/vFPqBoXRp5yL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xfYhgLqcDIhnSpwxIJKIluJReGTtD/4QpI1J1YKdrPlHL21Qhr/gyEGbl1Q4YHYypTwsqG5BOVv87nDHQFjDkWsrlSlUAHAUJWYnGzffgp+uZ/1VNeV9Uerq6pLevW5pbWlRFcvuunTJj1kw57fTTZer06VqabC1sET02Ptz9TgFsHhmGu3SVb7YVeK2c0xt93a699tpodXXl+7LZ/CfnzJl9ektzY6Stba/U19cE01qNWcAgWl2oZYswYvw/BgEGhIBV1TBGcmrsKsorNVNPedXXvvY16evrly9+8W+kr39AS5K8TIghfJd89hL59+99T0465RRpaGwsBMpQtNSWWnbJDCfgxDNEGtzSZRjMJIGKprSIv5O1gf0gm4cR05rhnGaRlAkBhGiGLpOxbF56UB1BQ22d/PL6G+Tcc86Vm2++UfbsadN9oDC1e/dO7QuBHcpl6a+w83LD7U7YA3k3luq8YXNU9rFMoJ9xgAxWoseFdfWJue7YeM+nAfMMuXN2h8B76tAofTGpI70WmBIAIaIAbMs98Bke/O4DInHE/O6Ax+6nyVHiLABD3gSpTElQfkcA4g6Kz4zv0QgDk/EAxAOV8d+JYhA1lgEZH9RM9F2aLEB7o3//XvPz229S+isDIC7pbJOiTTShsqJidGgwPbS3tfV/19XVPtTa3v37s846C/m3w/J6IwGQu9fcfPziY1ee39zYvHpoaOgskUg8EonGmB1kc5QOTtZM9vfJnu9XCkCsyZeMNrLcKR06+KUv/Z0wC+iMM06XTBZG24bl2RffMufeP2Y9EHaNfi3hQB1VwnBfHLbEVa/8++0BsbMZziC46hV/DwMQDZ49ARIz4Qz6CqwkNl5g5z1TT4CMP/A5IKgW8nndNsjeG+iwciWXFNbzUQVFa5b3hJafpz/zzhK7DbVek0DKPgS2nJHRWd+RiIIHPuv9fxy7mDQz0YJYLJ43AGN+sDA1PBan9Cqi7+VyasfxIVWVFeqXzT8kZIByW9SlMjmtHnBfnh8dzfPZA
I ONLY see the above value via inspect element, when I actually use `.get_attribute('src')` on the element, and print, it outputs this:
blob:https://express.adobe.com/31150ca9-e670-4165-a619-8cd95f2a5a6d
I am using Python Selenium to automate background removal via an online Adobe tool. I got all the way to downloading the image after the background is removed, but the img src is very strange and I am not sure how to download it.
This is the page: <https://express.adobe.com/tools/remove-background>
After uploading an image, the page removes the bg and shows a preview (on the same page). This is the image I am trying to download.
I tried using urllib requests to download it, but I get the error:
urllib.error.URLError: <urlopen error unknown url type: blob>
</details>
# 答案1
**得分**: 1
要下载图像,您可以将base64数据转换回二进制并将其保存为文件,例如:
```python
import base64
import io
from PIL import Image
data = "iVBORw0KGgoAAAANSUhEUgAAAyAAAAMgCAYAAADbcAZoAAAAAXNSR..." # 在这里使用您的base64字符串
if "data:image/png;base64," in data:
data = data.replace("data:image/png;base64,", "")
data_bytes = base64.b64decode(data)
image = Image.open(io.BytesIO(data_bytes))
image.save("output.png")
英文:
To download the image you can convert the base64 data back into binary and save it as a file, like for example:
import base64
import io
from PIL import Image
data = "iVBORw0KGgoAAAANSUhEUgAAAyAAAAMgCAYAAADbcAZoAAAAAXNSR..." # use your base64 string here
if "data:image/png;base64," in data:
data = data.replace("data:image/png;base64,", "")
data_bytes = base64.b64decode(data)
image = Image.open(io.BytesIO(data_bytes))
image.save("output.png")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论