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

selector-hound

v2.3.0

Published

Find an element that matches a particular CSS selector on a website

Downloads

5

Readme

Selector Hound: sniff out CSS Selectors on a site

SelectorHound lets you find CSS selectors on a public or local site. Rename, refactor, and delete unused CSS with a bloodhound on your side.

A sitemap or a site URL is enough to get started. Provide a single CSS selector, a comma separated string of selectors, or even a stylesheet.

Pages with zero matches aren't put in the results. Pages with at least one match are in the result, and you find out which CSS selectors aren't used. (That's right, it's a selector finder and ... "not founder").

Optionally take a screenshot of the elements (though it may hurt performance).

Pages not showing up that should? Check the log.txt for any issues.

Installation

Prerequisites

  • Node LTS (as of August 2024, Node 20.16.0)

Some possible Puppeteer setup for Mac Users

If you want to use the -d or -c (--isSpa and --takeScreenshots ) options, this requires Puppeteer which in turn requires Chromium.

You may (or may not) need PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true and PUPPETEER_EXECUTABLE_PATH environment variables set. They were necessary for older versions of Puppeteer and seem to be unnecessary for new ones.

If you're having issues, run printenv in your terminal to see if those variables are set. If they are, you may need to unset them with unset PUPPETEER_SKIP_CHROMIUM_DOWNLOAD and unset PUPPETEER_EXECUTABLE_PATH. Then source ~/.bashrc or source ~/.zshrc to be sure, and run printenv once again.

But if they aren't set, you may need to do this.

After you play with those variables, reinstall this package.

Running on-demand

Download this package. Then run

npm install

Globally via NPM

npm i -g selector-hound

Usage

Basic Scanning

Only scan the first 20 pages for .yourthing

SelectorHound --sitemap=https://wherever.com/xml --limit=20 --selector=".yourthing"
SelectorHound -u https://wherever.com/xml -l 20 -s ".yourthing"

Re-using, regenerating, and providing a list of links

Before the site scanning begins, this generates a <site>.sitemap.json file containing all of the links it will scan. This file is generated from the sitemap.xml file you provided or from crawling the site looking for links. To improve performance, SelectorHound will look for this file first before attempting to retrieve/generate a sitemap.

If you want to re-generate this <site>.sitemap.json file, you can force it:

SelectorHound --sitemap=https://wherever.com/xml  --selector=".yourthing" --dontUseExportedSitemap
SelectorHound -u https://mysite.com/landing -r -s '.yourThing' -X

Formatting

By default, SelectorHound will generate a format that's based off of how sitemap XML looks, which is an array of objects with a loc property:

[
    {
        'loc': 'https://mysite.com/path'
    },
    {
        'loc': 'https://mysite.com/another'
    }
]

However, you can also provide your own list of links as just an array of strings:

    [
        "https://mysite.com/path",
        "https://mysite.com/another"
    ]

Crawling instead of using a sitemap

Crawl the site, starting from a landing page.

SelectorHound -u https://mysite.com/landing -r -s ".myClass"

Taking Screenshots or dealing with SPAs

Scan the first 20 pages and take screenshots

SelectorHound -u https://wherever.com/xml -l 20 -s ".yourthing" -c

Scan those pages, but treat them like Single Page Applications (-d), and search for all the selectors in mystyles.css

SelectorHound -u https://wherever.com/xml -f "mystyles.css" -d

Options

| Option | Alias | Description | Defaults | |---|---|---|---| | --sitemap |-u | Must be fully qualified URL to an XML Sitemap or fully qualified URL to a page if crawl is true. Required. | https://frankmtaylor.com/sitemap.xml | | --dontUseExportedSitemap |-X | if a <site>.sitemap.json file has been already been created, ignore it and generate a new one. Optional. | false | | --limit | -l | Maximum number of pages to crawl. Optional. | 0 | | --selector | -s | A valid CSS selector. Required. | .title | | --cssFile | -f | A CSS file to use instead of a single selector. Optional. | | | --isSpa| -d | Uses Puppeteer instead of Cheerio (in case some content is dynamic). Optional. | false| | --takeScreenshots| -c | Takes screenshots with Puppeteer. Optional. | false | | --outputFileName | -o | A provided value will be prepended to pages.json and will be output in your current directory. Оptional. | pages.json | | --showElementDetails | -e | Show details for elements that match result (tag, innerText, attributes) . Optional. | false | | --showHtml | -m | Shows HTML of the elements that match the result. Optional. | true | | --crawl| -r | Crawls the site instead of using a sitemap. Outputs a file called <sitename>.sitemap.json. Optional. | false |