python - 如何在python中打开svg url
问题描述
我正在尝试编写一个从 wikipedia 抓取 svg url 的程序,我一直在做一些研究,但找不到打开指向 svg 文件的 url 的方法,所以我想知道是否有善良的灵魂可以将我指向正确的方向。
这是到目前为止的程序:
import requests
import os
from io import BytesIO
import matplotlib.pyplot as plt
from PIL import Image
import wikipedia
a = input("Enter drug: ")
piccies = wikipedia.page(a).images
matching = [s for s in piccies if "svg" in s]
print(matching[0])
response = requests.get(matching[0], stream=True)
print(response)
img = Image.open(response.raw)
plt.imshow(img)
plt.show()
以及我得到的当前错误:
Traceback (most recent call last):
File "scrape3.py", line 16, in <module>
img = Image.open(response.raw)
File "/home/alejandro/anaconda3/lib/python3.8/site-packages/PIL/Image.py", line 2943, in open
raise UnidentifiedImageError(
PIL.UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f06a67af310>
我在这里缺少什么?是因为我需要将 url 解码为 jpg 或 png 才能打开它吗?PS:我得到 svg id 以便稍后在 TKinter 代码上使用它的原因,所以如果有办法导出到 TKinter 标签或画布对象,我将不胜感激。谢谢
解决方案
推荐阅读
- jquery - ASP。NET MVC 数据表类型错误:$(...).DataTable 不是函数
- sql-server - 将###-###-####电话号码转换为字符串而不是数学运算
- sql - 有条件地从不同的表中选择
- python - 如何在 X 轴上设置刻度以仅在值更改时显示?
- java - 如何流式传输地图
> 到列表 包含绝对路径作为字符串? - reactjs - 样式化的组件会导致不需要的重新渲染
- symfony - Symfony 4:如何验证用户身份?
- tensorflow - tensorflow v2.0.0-alpha0 在 Windows 10 上构建错误“swif”
- module - 无法在 GNU prolog 中加载 library(readutil) 模块?
- python - pandas read_html - 找不到表