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

snapshooter

v0.3.9

Published

Simple crawler for Single Page Applications

Downloads

40

Readme

Snapshooter

Simple crawler for Single Page Applications.

Dependency Status NPM version

About

Snapshooter will load a URL, wait the javascript to render and save it as plain HTML.

This will be done recursively until all found links in the start URL is saved.

Issues

Do not hesitate to open a feature request or a bug report.

https://github.com/serpentem/snapshooter/issues

Docs

You'll need PhantomJS installed (v 1.9 or greater) in order to use this package.

  • http://phantomjs.org
npm install -g snapshooter
Usage:
  snapshooter [options] [params]

Options:
  -i, --input            Input url to index                                                 
  -o, --output           Output folder to save indexed files                                
  -e, --exclude          Regex pattern for excluding files (pass between quotes)            
  -p, --pretty           Output indexed files in a pretty fashion way                       
  -s, --server           Start a server for previewing indexed content                      
  -P, --port             Preview server port                                                  [default: 8080]
  -f, --forward          Avoid indexing links up to the initial url folder                  
  -t, --timeout          Time limit (in seconds) to wait for a page to render                 [default: 15]
  -m, --max-connections  Max connections limit, use with care                                 [default: 10]
  -l, --log              Show 'console.log' messages (try disabling it if phantom crashes)  
  -L, --live             Creates a "live" tunnel, crawling will happen on demand            
  -O, --once             Avoid recursivity, index only the given url and nothing else       
  -S, --stdout           Prints indexed content to stdout (auto-set -O=true -l=false)       
  -V, --verbose          Shows info logs about files skipped                                
  -D, --delete           Automatically delete destination folder before writing new files   
  -X, --overwrite        Automatically overwrite destination folder with new files          
  -H, --hidden           Doesn't inject the `window.snapshooter=true` on pages being indexed
  -v, --version          Shows snapshooter version                                          
  -h, --help             Shows this help screen                                             


Examples:
  snapshooter -i <site.com> -o <local-folder>
  snapshooter -i <site.com> -o <local-folder> -p
  snapshooter -i <site.com> -o <local-folder> -ps [-P 3000] [-e '/\.exe$/m'] [-t 20000]

A very tiny bit of integration is needed in order for it to effectively wait until all javascript opterations is done, such as data loadings, template rendering etc.

Considering you have a Single Page Application I bet you have also some render method, and possibly another in and out too for handling transitions.

Well, the only matter here is to inform Snapshooter that the page has finish rendering. It's achieved by setting the property window.crawler.is_rendered.

window.crawler.is_rendered = true

Snapshooter will keep waiting for the page until this variable gets true and then the rendered DOM will be saved as a plain html file.

We got ourselves many times having to "clean the DOM" before saving to file or just wanting to save the content without header and footer.

In order to achieve that we created the option to write a coffee file and filter the source just before it gets written to the HTML file.

In order to achieve filtering you must create a coffee file with a before_save method and specify that file with the "-k" option on the command line.

The method will be called and will receive a jQuery object which you can use to manipulate the DOM, you should return the piece of HTML you want to save.

# removing script tags from the DOM

exports.before_save = ( $ ) ->
  
  $.find( 'script' ).remove()

  return $.html()

# returning just the content div

exports.before_save = ( $ ) ->
  
  return $.find( '#content' ).html()

then from the command line

snapshooter -i <site.com> -o <local-folder> -k my_hook_file.coffee

Download the repo and have fun, pull requests are more than welcome.

Setting up

  git clone git://github.com/serpentem/snapshooter.git
  cd snapshooter
  npm link

Compiling

To build, just run:

make build

During develop you may prefer:

make watch

Attention

Do not mess with version number.

Powered by