Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/a11ywatch/crawler

gRPC web crawler turbo charged for performance
https://github.com/a11ywatch/crawler

a11ywatch crawler grpc scraper

Last synced: about 2 months ago
JSON representation

gRPC web crawler turbo charged for performance

Awesome Lists containing this project

README

        

# crawler

A [gRPC](https://grpc.io/) web indexer turbo charged for performance.

This project is capable of handling millions of pages per second efficiently.

## Getting Started

Make sure to have [Rust](https://doc.rust-lang.org/book/ch01-01-installation.html) installed or Docker.

This project requires that you start up another gRPC server on port `50051` following the [proto spec](https://github.com/a11ywatch/protobuf/blob/main/website.proto).

The user agent is spoofed on each crawl to a random agent and the indexer extends [spider](https://github.com/spider-rs/spider) as the base.

1. `cargo run` or `docker compose up`

## Installation

You can install easily with the following:

### Cargo

The [crate](https://crates.io/crates/website_crawler) is available to setup a gRPC server within rust projects.

```sh
cargo install website_crawler
```

### Docker

You can use also use the docker image at [a11ywatch/crawler](https://hub.docker.com/repository/docker/a11ywatch/crawler).

Set the `CRAWLER_IMAGE` env var to `darwin-arm64` to get the native m1 mac image.

```yml
crawler:
container_name: crawler
image: "a11ywatch/crawler:${CRAWLER_IMAGE:-latest}"
ports:
- 50055
```

### Node / Bun

We also release the package to npm [@a11ywatch/crawler](https://www.npmjs.com/package/@a11ywatch/crawler).

```sh
npm i @a11ywatch/crawler
```

After import at the top of your project to start the gRPC server or run node directly against the module.

```ts
import "@a11ywatch/crawler";
```

## Example

This is a basic example crawling a web page, add spider to your `Cargo.toml`:

```toml
[dependencies]
website_crawler = "0.9.4"
```

A basic [example](./examples/example.rs) can also be done with:

One terminal run the server

```sh
cargo run --example server --release
```

Another terminal run the client/server

```sh
cargo run --example client --release
```

https://user-images.githubusercontent.com/8095978/221221122-cfed83aa-6ca1-4122-a1db-0d9948e9f9d9.mov

### Dependencies

In order to build `crawler` locally >= 0.5.0, you need the `protoc` Protocol Buffers compiler, along with Protocol Buffers resource files.

#### Ubuntu

proto compiler needs to be at v3 in order to compile. Ubuntu 18+ auto installs.

```bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y protobuf-compiler libprotobuf-dev
```

#### Alpine Linux

```sh
sudo apk add protoc protobuf-dev
```

#### macOS

Assuming [Homebrew](https://brew.sh/) is already installed. (If not, see instructions for installing Homebrew on [the Homebrew website](https://brew.sh/).)

```zsh
brew install protobuf
```

### Features

1. `jemalloc` - use jemalloc memory allocator (default disabled).
1. `regex` - use the regex crate for blacklist urls validation.
1. `ua_generator` - use the ua_generator crate to spoof random user agent.
1. `smart` - use smart mode to run HTTP request first and chrome when JS is needed.
1. `chrome`: Enables chrome headless rendering, use the env var `CHROME_URL` to connect remotely.

## About

This crawler is optimized for reduced latency and uses isolated based concurrency as it can handle over 10,000 pages within several milliseconds. In order to receive the links found for the crawler you need to add the [`website.proto`](./proto/website.proto) to your server. This is required since every request spawns a thread. Isolating the context drastically improves performance (preventing shared resources / communication ).

## Help

If you need help implementing the gRPC server to receive the pages or links when found check out the [gRPC node example](https://github.com/A11yWatch/a11ywatch-core/blob/main/src/proto/website-server.ts) for a starting point .

## LICENSE

Check the license file in the root of the project.