add single page html to md
This commit is contained in:
+19
-11
@@ -41,6 +41,7 @@ pub struct Scraper {
|
||||
include_types: Option<HashSet<String>>,
|
||||
exclude_types: Option<HashSet<String>>,
|
||||
scope_path: Option<String>,
|
||||
single_page: bool,
|
||||
}
|
||||
|
||||
impl Scraper {
|
||||
@@ -54,6 +55,7 @@ impl Scraper {
|
||||
include_types: Option<HashSet<String>>,
|
||||
exclude_types: Option<HashSet<String>>,
|
||||
scope_path: Option<String>,
|
||||
single_page: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
fetcher,
|
||||
@@ -67,6 +69,7 @@ impl Scraper {
|
||||
include_types,
|
||||
exclude_types,
|
||||
scope_path,
|
||||
single_page,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,20 +167,24 @@ impl Scraper {
|
||||
}
|
||||
|
||||
if is_html {
|
||||
if let Ok(html) = std::str::from_utf8(&result.bytes) {
|
||||
let links = extract_links(html, &final_url, &self.base_domain);
|
||||
let new_count = links.len();
|
||||
if !self.single_page {
|
||||
if let Ok(html) = std::str::from_utf8(&result.bytes) {
|
||||
let links = extract_links(html, &final_url, &self.base_domain);
|
||||
let new_count = links.len();
|
||||
|
||||
let new_links: Vec<Url> = links
|
||||
.into_iter()
|
||||
.filter(|link| !self.seen.contains(link.as_str()))
|
||||
.collect();
|
||||
let new_links: Vec<Url> = links
|
||||
.into_iter()
|
||||
.filter(|link| !self.seen.contains(link.as_str()))
|
||||
.collect();
|
||||
|
||||
for link in &new_links {
|
||||
queue.push_back(link.clone());
|
||||
for link in &new_links {
|
||||
queue.push_back(link.clone());
|
||||
}
|
||||
|
||||
log::info!(" found {} links ({} new)", new_count, new_links.len());
|
||||
}
|
||||
|
||||
log::info!(" found {} links ({} new)", new_count, new_links.len());
|
||||
} else {
|
||||
log::info!(" [single-page mode] not crawling for links");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -303,6 +310,7 @@ mod tests {
|
||||
include_types,
|
||||
exclude_types,
|
||||
scope_path: None,
|
||||
single_page: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user