fix: handle failed image fetch
This commit is contained in:
parent
3ddc5123d2
commit
df1bb8cdd8
1 changed files with 11 additions and 7 deletions
|
|
@ -162,13 +162,17 @@ class SnapshotCamera:
|
||||||
for element in body.select(", ".join(self.config.article_body_remove_selector)):
|
for element in body.select(", ".join(self.config.article_body_remove_selector)):
|
||||||
element.decompose()
|
element.decompose()
|
||||||
for image in body.select("img"):
|
for image in body.select("img"):
|
||||||
image.attrs = {
|
img_src = fetch_url(
|
||||||
"src": fetch_url(
|
pangea_expanded_image_url(self.url),
|
||||||
pangea_expanded_image_url(self.url),
|
image.get("src", image.get("data-src", ""))
|
||||||
image.get("src", image.get("data-src", "")),
|
)
|
||||||
),
|
if img_src:
|
||||||
"alt": image.get("alt", ""),
|
image.attrs = {
|
||||||
}
|
"src": img_src,
|
||||||
|
"alt": image.get("alt", ""),
|
||||||
|
}
|
||||||
|
else:
|
||||||
|
image.decompose()
|
||||||
with get_db_session() as db:
|
with get_db_session() as db:
|
||||||
for hyperlink in body.select("a"):
|
for hyperlink in body.select("a"):
|
||||||
absolute_url = urljoin(self.url, hyperlink.get("href"))
|
absolute_url = urljoin(self.url, hyperlink.get("href"))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue