Giter Club home page Giter Club logo

crawler's Introduction

Crawler

It comprises of two main modules:

  • a REST API server that shows the web page information stored in the database;
  • a CLI crawler used to crawl web pages and populate the database.

Building and Running with Docker

Build the image.

$ docker build -t crawler .

Start the REST API server.

You need to adjust the MongoDB connection string according to your server.

$ docker run --rm -d --name crawler -p 3000:3000 \
-e MONGODB_URL="mongodb+srv://<user>:<password>@<host>/<db>?retryWrites=true&w=majority" \
crawler

Query the REST API server.

The examples below use jq to format the JSON responses in a human-readable way.

$ curl -s 'http://localhost:3000/pages?offset=0&limit=5' | jq .
$ curl -s 'http://localhost:3000/pages/1bab3f16e219f6242b86db0c18e33cfd' | jq .

Start crawling a web page. The example below starts a crawler that visits 100 pages beginning at https://www.crawler-test.com/.

You need to adjust the MongoDB connection string according to your server.

$ docker run --rm -it \
-e MONGODB_URL="mongodb+srv://<user>:<password>@<host>/<db>?retryWrites=true&w=majority" \
crawler bin/crawl --maxVisits 100 https://www.crawler-test.com/

Developing

You need at Node.js version 12 or above (it will probably work on other versions with proper async/await support).

Create a .env file containing the MONGODB_URL variable.

You need to adjust the MongoDB connection string according to your server.

$ echo MONGODB_URL="mongodb+srv://<user>:<password>@<host>/<db>?retryWrites=true&w=majority" > .env

Install dependencies.

$ npm install

Run unit tests continuously and code.

$ npm run test:watch

Debug the REST API server.

npm start

Debug the crawler CLI.

$ npm run cli:debug -- --maxVisits 1 https://www.crawler-test.com/

Tools

You may want to run the commands above (to debug stuff) in a terminal within Visual Studio Code because it auto-attaches its debugger.

Visual Studio Code is automatically configured to reformat code on save. You will need its Prettier, ESLint and EditorConfig extensions.

There is also a Husky git commit hook to run ESLint and Prettier before any git commit.

crawler's People

Contributors

mhnagaoka avatar dependabot[bot] avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.