Skip to content

Commit

Permalink
#5 Add skelbiu-lt listing updated_at scraping
Browse files Browse the repository at this point in the history
  • Loading branch information
zexa committed Oct 11, 2021
1 parent 71e591e commit c12962b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
15 changes: 14 additions & 1 deletion skelbiu-lt-scraper/src/skelbiu_lt_listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@ pub struct SkelbiuLtListing {
title: String,
description: String,
views: String,
updated_at: String,
}

impl SkelbiuLtListing {
pub fn new(url: String, id: String, title: String, description: String, views: String) -> Self {
pub fn new(
url: String,
id: String,
title: String,
description: String,
views: String,
updated_at: String,
) -> Self {
Self {
url,
id,
title,
description,
views,
updated_at,
}
}

Expand All @@ -35,6 +44,10 @@ impl SkelbiuLtListing {
pub fn get_views(&self) -> &str {
&self.views
}

pub fn get_updated_at(&self) -> &str {
&self.updated_at
}
}

impl Listing for SkelbiuLtListing {
Expand Down
14 changes: 14 additions & 0 deletions skelbiu-lt-scraper/src/skelbiu_lt_listing_scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ pub struct SkelbiuLtListingScraper {
title_selector: Selector,
description_selector: Selector,
view_selector: Selector,
updated_at_selector: Selector,
}

impl SkelbiuLtListingScraper {
Expand All @@ -15,17 +16,20 @@ impl SkelbiuLtListingScraper {
title_selector: String,
description_selector: String,
view_selector: String,
updated_at_selector: String,
) -> Self {
let id_selector = Selector::parse(id_selector.as_str()).unwrap();
let title_selector = Selector::parse(title_selector.as_str()).unwrap();
let description_selector = Selector::parse(description_selector.as_str()).unwrap();
let view_selector = Selector::parse(view_selector.as_str()).unwrap();
let updated_at_selector = Selector::parse(updated_at_selector.as_str()).unwrap();

Self {
id_selector,
title_selector,
description_selector,
view_selector,
updated_at_selector,
}
}
}
Expand Down Expand Up @@ -73,12 +77,22 @@ impl ListingScraper<SkelbiuLtListing> for SkelbiuLtListingScraper {
.trim()
.to_string();

let updated_at = html
.select(&self.updated_at_selector)
.next()
.unwrap()
.text()
.collect::<String>()
.trim()
.replace("Atnaujintas ", "");

return Some(SkelbiuLtListing::new(
listing_url,
id,
title,
description,
views,
updated_at,
));
}

Expand Down
1 change: 1 addition & 0 deletions skelbiu-lt-scraper/src/skelbiu_lt_scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ impl CommonScrapper<SkelbiuLtListing> for SkelbiuLtScraper {
"h1[itemprop=name]".to_string(),
".description".to_string(),
".showed".to_string(),
"div[class='block']".to_string(),
))
}

Expand Down

0 comments on commit c12962b

Please sign in to comment.