chore(scraper): changes made based on review comments

This commit is contained in:
Ken Snyder
2022-02-18 10:20:08 -08:00
parent f68507d30a
commit 760515e720
3 changed files with 23 additions and 17 deletions

View File

@@ -110,12 +110,17 @@ pub struct Document {
impl Document {
pub fn new(url: &str) -> Document {
let url = match url.starts_with("http") {
true => url.to_string(),
false => ["https://", url].join(""),
};
Document { url, data: None }
if url.starts_with("http") {
Document {
url: url.to_string(),
data: None,
}
} else {
Document {
url: ["https://", url].join(""),
data: None,
}
}
}
/// Loads the HTTP page over the network and saves as a string
@@ -322,7 +327,7 @@ impl ParsedDoc {
pub fn child_selectors(mut self, selectors: Vec<&str>, scope: ChildScope) -> Self {
let new_selectors: Vec<(String, ChildScope)> = selectors
.iter()
.map(|s| (s.to_string(), scope.clone()))
.map(|s| ((*s).to_string(), scope.clone()))
.collect();
new_selectors

View File

@@ -33,11 +33,10 @@ pub fn text(el: &ElementRef) -> Option<String> {
}
pub fn html(el: &ElementRef) -> Option<String> {
let html = el.inner_html();
if html.is_empty() {
if el.inner_html().is_empty() {
None
} else {
Some(html)
Some(el.inner_html().trim().to_string())
}
}
@@ -62,12 +61,14 @@ pub fn type_(el: &ElementRef) -> Option<String> {
}
pub fn disabled(el: &ElementRef) -> Option<bool> {
match el.value().attr("disabled") {
Some(v) => match v {
"true" => Some(true),
_ => Some(false),
},
None => None,
if let Some(d) = el.value().attr("disabled") {
if d == "true" {
Some(true)
} else {
Some(false)
}
} else {
None
}
}

View File

@@ -19,7 +19,7 @@ struct Args {
follow: bool,
#[clap(long)]
/// Show the structs discovered
/// Show a selector as part of console output
show: Option<String>,
}
pub mod document;