mirror of
https://gitlab.com/news-flash/article_scraper.git
synced 2025-07-08 08:30:00 +02:00
start implementing readability
This commit is contained in:
parent
c08f5afa5d
commit
2750ad648d
10 changed files with 375 additions and 124 deletions
11
src/util.rs
11
src/util.rs
|
@ -145,6 +145,17 @@ impl Util {
|
|||
None
|
||||
}
|
||||
|
||||
pub fn get_attribute(
|
||||
context: &Context,
|
||||
xpath: &str,
|
||||
attribute: &str,
|
||||
) -> Result<String, FullTextParserError> {
|
||||
Util::evaluate_xpath(context, xpath, false)?
|
||||
.iter()
|
||||
.find_map(|node| node.get_attribute(attribute))
|
||||
.ok_or(FullTextParserError::Xml)
|
||||
}
|
||||
|
||||
pub fn extract_value(context: &Context, xpath: &str) -> Result<String, FullTextParserError> {
|
||||
let node_vec = Util::evaluate_xpath(context, xpath, false)?;
|
||||
if let Some(val) = node_vec.get(0) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue