1
0
Fork 0
mirror of https://gitlab.com/news-flash/article_scraper.git synced 2025-07-07 08:05:31 +02:00
This commit is contained in:
Jan Lukas Gernert 2024-02-13 19:35:29 +01:00
parent b13673ce3b
commit a1ee3b22f9

View file

@ -1,5 +1,5 @@
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt::Write;
use libxml::{ use libxml::{
tree::{Document, Node, NodeType, SaveOptions}, tree::{Document, Node, NodeType, SaveOptions},
xpath::Context, xpath::Context,
@ -190,7 +190,7 @@ impl Util {
pub fn extract_value(context: &Context, xpath: &str) -> Result<String, FullTextParserError> { pub fn extract_value(context: &Context, xpath: &str) -> Result<String, FullTextParserError> {
let node_vec = Util::evaluate_xpath(context, xpath, false)?; let node_vec = Util::evaluate_xpath(context, xpath, false)?;
if let Some(val) = node_vec.get(0) { if let Some(val) = node_vec.first() {
return Ok(val.get_content()); return Ok(val.get_content());
} }
@ -207,8 +207,10 @@ impl Util {
let part = node let part = node
.get_content() .get_content()
.split_whitespace() .split_whitespace()
.map(|s| format!("{} ", s)) .fold(String::new(), |mut output, s| {
.collect::<String>(); let _ = write!(output, " {s}");
output
});
val.push_str(&part); val.push_str(&part);
val.push(' '); val.push(' ');
} }