Simply add this to your Cargo.toml
[dependencies]
crusty-core = "~0.2.2"
TITLE
tagsif you are in a hurry: ```rust use crusty_core::prelude::*;
pub struct JobState { sumtitlelen: usize }
pub struct TaskState { title: String }
pub struct DataExtractor {}
impl TaskExpander
async fn main() -> anyhow::Result<()> { let crawler = Crawler::new_default()?;
let settings = config::CrawlingSettings::default();
let rules = CrawlingRules::default().with_task_expander(|| DataExtractor{} );
let job = Job::new("https://bash.im", settings, rules, JobState::default())?;
for r in crawler.iter(job) {
println!("- {}, task state: {:?}", r, r.context.task_state);
if let JobStatus::Finished(_) = r.status {
println!("final job state: {:?}", r.context.job_state.lock().unwrap());
}
}
Ok(())
} ```
If you want to get more fancy and configure some stuff or control your imports more precisely ```rust use crusty_core::{ ParserProcessor, CrawlingRules, CrawlingRulesOptions, Crawler, TaskExpander, types::{ Job, JobCtx, Task, HttpStatus, JobStatus, select::predicate::Name, select::document::Document }, config, };
pub struct JobState { sumtitlelen: usize }
pub struct TaskState { title: String }
pub struct DataExtractor {}
impl TaskExpander
async fn main() -> anyhow::Result<()> { let concurrencyprofile = config::ConcurrencyProfile::default(); let pp = ParserProcessor::spawn(concurrencyprofile, 1024 * 1024 * 32);
let networking_profile = config::NetworkingProfile::default().resolve()?;
let crawler = Crawler::new(networking_profile, &pp);
let settings = config::CrawlingSettings::default();
let rules_opt = CrawlingRulesOptions::default();
let rules = CrawlingRules::new(rules_opt).with_task_expander(|| DataExtractor{} );
let job = Job::new("https://bash.im", settings, rules, JobState::default())?;
for r in crawler.iter(job) {
println!("- {}, task state: {:?}", r, r.context.task_state);
if let JobStatus::Finished(_) = r.status {
println!("final job state: {:?}", r.context.job_state.lock().unwrap());
}
}
Ok(pp.join().await??)
} ```
Please see examples for more complicated usage scenarios. This crawler is more verbose than some others, but it allows incredible customization at each and every step.
If you are interested in the area of broad web crawling there's crusty, developed fully on top of crusty-core
that tries to tackle on some challenges of broad web crawling