I am trying to write a program that scrapes a svg url from wikipedia, I have been doing quite some research and cannot find a way to open the url, which points to a svg file, so I wonder if some kind soul can point me into the right direction.
Here is the program so far:
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()
and the current error that I am getting:
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>
What I am missing here? is it because I need to decode the url to a jpg or png before I can open it? PS: The reason I am getting the svg id to use it later on a TKinter code, so if there is a way to export into a TKinter label or a canvas object I'll be most thankful. Thanks