mirror of
https://github.com/tauri-apps/tauri-search.git
synced 2026-02-04 02:41:20 +01:00
chore(scraper): changes made based on review comments
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user