Skip to content

Commit

Permalink
#5 Add description
Browse files Browse the repository at this point in the history
  • Loading branch information
zexa committed Oct 11, 2021
1 parent 8c10fa1 commit 6425ae3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
9 changes: 7 additions & 2 deletions skelbiu-lt-scraper/src/skelbiu_lt_listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@ use common_scraper::Listing;
pub struct SkelbiuLtListing {
url: String,
title: String,
description: String,
}

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

fn get_title(&self) -> &str {
Expand Down
21 changes: 17 additions & 4 deletions skelbiu-lt-scraper/src/skelbiu_lt_listing_scraper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@ use scraper::Selector;

pub struct SkelbiuLtListingScraper {
title_selector: Selector,
description_selector: Selector,
}

impl SkelbiuLtListingScraper {
pub fn new(title_selector: String) -> Self {
pub fn new(title_selector: String, description_selector: String) -> Self {
let title_selector = Selector::parse(title_selector.as_str()).unwrap();
let description_selector = Selector::parse(description_selector.as_str()).unwrap();

Self { title_selector }
Self {
title_selector,
description_selector,
}
}
}

Expand All @@ -26,11 +31,19 @@ impl ListingScraper<SkelbiuLtListing> for SkelbiuLtListingScraper {
.unwrap()
.text()
.collect::<String>()
.replace("\\n", "")
.trim()
.to_string();

return Some(SkelbiuLtListing::new(listing_url, title));
let description = html
.select(&self.description_selector)
.next()
.unwrap()
.text()
.collect::<String>()
.trim()
.to_string();

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

None
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 @@ -28,6 +28,7 @@ impl CommonScrapper<SkelbiuLtListing> for SkelbiuLtScraper {
// TODO: Refactor this to use DI & clone
Box::new(SkelbiuLtListingScraper::new(
"h1[itemprop=name]".to_string(),
".description".to_string(),
))
}

Expand Down

0 comments on commit 6425ae3

Please sign in to comment.