From 4fd41d98cc1c1a7e0a4f9c3d4ddf793aeebdd005 Mon Sep 17 00:00:00 2001 From: Jan Lukas Gernert Date: Mon, 26 Jun 2023 23:22:08 +0200 Subject: [PATCH] add fn to parse thumbnail from html --- article_scraper/src/full_text_parser/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/article_scraper/src/full_text_parser/mod.rs b/article_scraper/src/full_text_parser/mod.rs index c389a8d..b714827 100644 --- a/article_scraper/src/full_text_parser/mod.rs +++ b/article_scraper/src/full_text_parser/mod.rs @@ -427,6 +427,15 @@ impl FullTextParser { conf } + pub fn thumbnail_from_html(html: &str) -> Option { + if let Ok(doc) = Self::parse_html(html, None, &ConfigEntry::default()) { + if let Ok(ctx) = Self::get_xpath_ctx(&doc) { + return Self::check_for_thumbnail(&ctx); + } + } + None + } + pub fn check_for_thumbnail(context: &Context) -> Option { if let Ok(thumb) = Util::get_attribute( context,