I've just found out that the package cannot handle a page like https://telegram.com/
In [2]: link_preview("https://telegram.com/").image
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
Cell In[2], line 1
----> 1 link_preview("https://telegram.com/").image
File ~/workspace/lomavis/webapp/venv/lib/python3.11/site-packages/linkpreview/helpers.py:33, in LazyAttribute.__get__(self, obj, t)
31 if obj is None:
32 return f
---> 33 val = f(obj)
34 setattr(obj, f.__name__, val)
35 return val
File ~/workspace/lomavis/webapp/venv/lib/python3.11/site-packages/linkpreview/linkpreview.py:50, in LinkPreview.image(self)
48 @LazyAttribute
49 def image(self):
---> 50 return self._find_attribute("image")
File ~/workspace/lomavis/webapp/venv/lib/python3.11/site-packages/linkpreview/linkpreview.py:32, in LinkPreview._find_attribute(self, name)
30 def _find_attribute(self, name):
31 for obj in self.sources:
---> 32 value = getattr(obj, name)
33 if value:
34 return value
File ~/workspace/lomavis/webapp/venv/lib/python3.11/site-packages/linkpreview/preview/generic.py:66, in Generic.image(self)
62 else:
63 # just find something
64 img = soup.find("img")
---> 66 if img and img["src"]:
67 return img["src"]
File ~/workspace/lomavis/webapp/venv/lib/python3.11/site-packages/bs4/element.py:1406, in Tag.__getitem__(self, key)
1403 def __getitem__(self, key):
1404 """tag[key] returns the value of the 'key' attribute for the Tag,
1405 and throws an exception if it's not there."""
-> 1406 return self.attrs[key]
KeyError: 'src'
I've just found out that the package cannot handle a page like https://telegram.com/