npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

cameo-crawler

v0.3.0

Published

Crawl the web breadth-first from a seed url, statefully

Downloads

7

Readme

cameo-crawler

There are already tens of Node.js scripts that spider / crawl sites, and many more Python and Ruby ones. It isn't clear how many of them they work, or that they even recurse. Or if they do, is it depth-first? Breadth-first?

This project is a work in progress. I intend to document at least its philosophy, if not methodology, better than the competition.

It's ruthless (this package used to be called "ruthless") in that it does not respect robots.txt. So, you're on your own if you violate some vengeful site's TOS.

Current philosophy

I wanted a stateful queue, in case of stops or restarts. Redis was the first choice, but I had too much metadata. So I'm using Postgres right now. Not sure if that's the best idea. The pages table has these columns:

id, parent_id, url, tag, depth, content, plaintext, queued, fetched, failed, error

The pages table:

  • Seed urls are accompanied by a freeform tag, and enter the database with a depth of 0.
  • The pages they link to inherit that tag, have a parent_id set to the linking page's id.
  • The child pages have a depth of depth + 1 if they are on the same domain (protocol and subdomain insensitive), or depth + 100 if they do not share the domain (defined by the hostname field that Node.js's Url.parse(urlStr) produces).
  • The crawl proceeds breadth-first, so the depth never needs to be updated.

Here is an sample of depths retrieved for a single seed site (a blog) that I let run for a couple of minutes:

SELECT depth, COUNT(depth) FROM pages GROUP BY depth ORDER BY depth;

Depth  Count
    0      1
    1     81
    2    319
    3    731
    4    851
  100     22
  101    151
  102   1071
  103   1593

As it was, I hadn't gotten through the 3-deep sites yet.

Initialization

If the supplied credentials have superuser privileges, the database and pages table will be created automatically.

Otherwise, run the following at your command line to initialize (and reset) everything to the defaults:

dropdb cameo-crawler; createdb cameo-crawler && psql cameo-crawler < schema.sql

TODO

  • Use cluster to spawn multiple workers. It's currently kind of slow, because most things happen in series.
  • The seen cache can handle most locking issues; as soon as work() fetches a new url, add the url to seen. Even if a page is fetched twice, it's not a big deal!
  • Allow a threshold depth, i.e., stop after going 10 links deep into a seed url.
  • Allow constraining a query to a single domain.

License

Copyright © 2012–2014 Christopher Brown. MIT Licensed.