Code Monkey home page Code Monkey logo

webcrawler's Introduction

WebCrawler

A simple web crawler CLI application.

The aim of the application is to enumerate all the links for each page on a given domain. The result of the crawl will be output to a JSON file in the results under the crawl domain e.g. https://wiprodigital.com -> /results/wiprodigital.com.json (a sample has been included)

There are some caveats:

  • The application will automatically exclude JS / CSS URLs
  • The application will not crawl external URLs
  • The application will not crawl sub-domain URLs e.g. test.wiprodigital.com

Installing

Node v7.6+ required

npm i

Running

npm start <domain>

Note - <domain> may also be set as an environment variable START_URL, if both values are used the CLI takes precedence

Testing

npm test

Notes

  • Applied SRP for scraping (HttpPage) and traversing (WebCrawler)
  • Made use of Map to dedupe links
  • Used recursion to traverse pages
  • Took the decision to not create an "exporter" or "deserializer" class, given the native support in Node for JSON serialization & file exporting. However, if the application needed to support various export types then this would perhaps be a good approach to introduce a common interface.

TODO

  • Improve performance and speed of crawl e.g. run scrapes in parallel, use pm2 to scale out (although we need to be wary of race conditions, would need a mutex of some kind)
  • Include additional processing options e.g. max page depth, rate-limiting (protect against 429 errors)
  • Decouple HTML parsing from HttpPage class (maybe down the line we want to move away from cheerio)
  • Move results deserialization / file exporting to separate classes
  • Avoid crawling CMS-related URLs (/xmlrpc.php, /wp-json etc.)
  • Better handling of erroneous but valid URLs e.g. http://domain.com//a/b/c, crawler would currently treat //a as the domain in itself
  • Better hashtag URL processing (although the page is the same, they may pull dynamic content)
  • Better file name validation
  • Include stats e.g. total links found, pages crawled, crawl times etc.
  • Include more unit tests (happy-day, edge-case, error scenarios)
  • Include integration tests (validate against a real URL)
  • Implement Babel to leverage ES2017 syntax (i.e. yield, Object.fromEntries)
  • Improve parameter validation (or better yet, use TypeScript)
  • Improve instrumentation, utilise remote services like Loggly, Prometheus or equivalent
  • Perf tests against readily available libs like crawler, make sure you are reinventing the wheel for good reason

webcrawler's People

Contributors

jameshowe avatar

Watchers

 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.