Spider
Multithreaded async crawler/indexer using isolates and IPC channels for communication with the ability to run decentralized.
Dependencies
On Linux
- OpenSSL 1.0.1, 1.0.2, 1.1.0, or 1.1.1
Example
This is a basic async example crawling a web page, add spider to your Cargo.toml:
[]
= "1.26.3"
And then the code:
extern crate spider;
use Website;
use tokio;
async
You can use Configuration object to configure your crawler:
// ..
let mut website: Website = new;
website.configuration.blacklist_url.push;
website.configuration.respect_robots_txt = true;
website.configuration.subdomains = true;
website.configuration.tld = false;
website.configuration.delay = 0; // Defaults to 0 ms due to concurrency handling
website.configuration.request_timeout = None; // Defaults to 15000 ms
website.configuration.channel_buffer = 100; // Defaults to 50 - tune this depending on on_link_find_callback
website.configuration.user_agent = "myapp/version".to_string; // Defaults to spider/x.y.z, where x.y.z is the library version
website.on_link_find_callback = Some; // Callback to run on each link find
website.crawl.await;
Regex Blacklisting
There is an optional "regex" crate that can be enabled:
[]
= { = "1.26.3", = ["regex"] }
extern crate spider;
use Website;
use tokio;
async
Features
We have a couple optional feature flags. Regex blacklisting, jemaloc backend, decentralization, serde, gathering full assets, and randomizing User-Agents.
[]
= { = "1.26.3", = ["regex", "ua_generator"] }
ua_generator: Enables auto generating a random real User-Agent. Enabled by default.regex: Enables blacklisting paths with regxjemalloc: Enables the jemalloc memory backend.decentralized: Enables decentralized processing of IO, requires the [spider_worker] startup before crawls.control: Enabled the ability to pause, start, and shutdown crawls on demand.full_resources: Enables gathering all content that relates to the domain like css,jss, and etc.serde: Enables serde serialization support.
Jemalloc performs better for concurrency and allows memory to release easier.
This changes the global allocator of the program so test accordingly to measure impact.
[]
= { = "1.26.3", = ["jemalloc"] }
Blocking
If you need a blocking sync imp use a version prior to v1.12.0.
Pause, Resume, and Shutdown
If you are performing large workloads you may need to control the crawler by enabling the control feature flag:
extern crate spider;
use tokio;
use Website;
async
Shutdown crawls
Enable the control feature flag:
extern crate spider;
use tokio;
use Website;
async
Scrape/Gather HTML
extern crate spider;
use tokio;
use Website;
async
Decentralization
- cargo install
spider_worker. spider_worker.SPIDER_WORKER=http://127.0.0.1:3030 cargo run --example example --features decentralized
Use SPIDER_WORKER env variable to adjust the spider worker onto a load balancer.
The proxy needs to match the transport type for the request to fullfill correctly.
If the scrape feature flag is use the SPIDER_WORKER_SCRAPER env variable to determine the scraper worker.