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

orgasmatron

v0.1.2

Published

Easily scrape websites for html header meta data

Downloads

11

Readme

Orgasmatron - HTML head tag extractor

A simple easy to use HTML head scraper that provides a clean interface for extracting data from the tags within the head tag.

Wikipedia - The Orgasmatron is a manually operated head massage device made of partially flexible copper wires attached to a handle. The device has been specifically designed to gently massage the head and the back of the neck.

Full access to all head tags

The usage is simple and familiar. Just provide a url and callback function and it will be supplied with an accessor object that you can use to extract head tags.

var scraper = require('orgasmatron');
scraper('http://www.google.com', function(err, bundle){
  bundle.findWhere('meta', {name: 'description'});
});

The above looks for the first meta tag that has an attribute called name set to the value 'description'. In this case you would get back the object:

{ content: 'Search the world\'s information, including webpages, images, videos and more. Google has many special features to help you find exactly what you\'re looking for.',
  name: 'description' }

Installation

npm install orgasmatron

Project goals

  • Easy to learn
  • Leaves head tags in their original form
  • Flexibly allows you to extract data

API

Scraper

The require call returns a function that expects a url string and a callback function.

function (url, callback)

The callback function takes two parameters, (err, bundle) where bundle is an accessor object for finding head tags.

Extracting data

The data bundle provides methods for accessing data.

.where(tag, attributes)

Returns a list of all element objects that have the same tag string as the argument tag, and matches the attributes object. The attributes object defines attribute keys that must exist, as well as the values that must match them. If an attribute key is provided but the value is null or undefined, the attribute is checked to exist, but the value may be any value.

.findWhere(tag, attributes)

Returns the first element object that matches using the same criterion of .where.

Examples:

<meta property="og:type" content="website" />
<meta property="og:title" content="My First Website" />
<meta property="og:description" content="This is my first website, I hope you enjoy!" />

If you want to match any meta tag that has the content attribute set you can call the .where method with the key defined with no value in the attributes object.

bundle.where('meta', {content: undefined});

That would return all meta tags with a content attribute.

[{property: 'og:type', content: 'website'},
 {property: 'og:title' content: 'My First Website'},
 {property: 'og:description' content: 'This is my first website, I hope you enjoy!'}]

If you only wanted meta tags with property set to og:title, you would provide an attribute object with a key property set to the string og:title. Using findWhere would stop looking after finding the first element that matches.

bundle.findWhere('meta', {property: 'og:title'});

That would only return the first meta tag with a an attribute of property set to og:title.

{property: 'og:title' content: 'My First Website'}