Skip to content

Commit

Permalink
#5 Fix skelbiu-lt description can sometimes be null
Browse files Browse the repository at this point in the history
  • Loading branch information
zexa committed Oct 12, 2021
1 parent 0787a4f commit f3fd2b3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 3 additions & 3 deletions skelbiu-lt-scraper/src/skelbiu_lt_listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub struct SkelbiuLtListing {
url: String,
id: String,
title: String,
description: String,
description: Option<String>,
views: String,
updated_at: String,
liked_amount: String,
Expand All @@ -20,7 +20,7 @@ impl SkelbiuLtListing {
url: String,
id: String,
title: String,
description: String,
description: Option<String>,
views: String,
updated_at: String,
liked_amount: String,
Expand Down Expand Up @@ -50,7 +50,7 @@ impl SkelbiuLtListing {
&self.title
}

pub fn get_description(&self) -> &str {
pub fn get_description(&self) -> &Option<String> {
&self.description
}

Expand Down
26 changes: 16 additions & 10 deletions skelbiu-lt-scraper/src/skelbiu_lt_listing_scraper.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::skelbiu_lt_listing::SkelbiuLtListing;
use common_scraper::{ListingScraper, PotentialListing};
use scraper::Selector;
use scraper::{ElementRef, Selector};
use slog::Logger;

pub struct SkelbiuLtListingScraper {
Expand Down Expand Up @@ -75,15 +75,21 @@ impl ListingScraper<SkelbiuLtListing> for SkelbiuLtListingScraper {
.to_string();
debug!(self.logger, "Found title for {}", &listing_url);

let description = html
.select(&self.description_selector)
.next()
.unwrap_or_else(|| panic!("Could not find description for {}", &listing_url))
.text()
.collect::<String>()
.trim()
.to_string();
debug!(self.logger, "Found description for {}", &listing_url);
let description = match html.select(&self.description_selector).next() {
None => {
debug!(
self.logger,
"Could not find description for {}", &listing_url
);

None
}
Some(description) => {
debug!(self.logger, "Found description for {}", &listing_url);

Some(description.text().collect::<String>().trim().to_string())
}
};

let mut id = html
.select(&self.id_selector)
Expand Down

0 comments on commit f3fd2b3

Please sign in to comment.