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

os-cheerio-helper

v1.0.2

Published

an intuitive module to help with cheerio web scraping related functions

Downloads

7

Readme

Introduction

This project meant to provide intuitive functions to use cheeriojs, without wasting time.

When to use this library

If you just want to make an automated program, for navigating to a website and click on buttons, fill forms etc... so you should only use os-puppeteer.

Else you want to analyze a DOM of a website more thoroughly, this is the library.

Installation and use

The cheerio helper works in hand with os-puppeteer. So you'll need to npm i it too.

Install via npm: npm i os-puppeteer-helper npm i os-cheerio-helper

Require ch and ph:

var ch = require("os-cheerio-helper")
var ph = require("os-puppeteer-helper")

Quick start

Create a browser:

let bt = await ph.createBrowser(url, slowMo = 5, headless = false, width = 1300, height = 768)
    
// save the page and the browser
let browser = bt[0];
let page = bt[1];
    
    

Scrape the DOM:

let dom = await ch.getCheerioDom(page);

Find an element by a selector:

let receiptContainerList = await ch.getElementFromDom(dom, "tbody[id='the-list'] tr");

Get the first element from a list of elements:

let firstContainer = await ch.getElementAt(receiptContainerList, 0)

Get text from element:

await ch.getTextFromElement(firstContainer)   

Get other attribute value from element:

await ch.getAttributeValueFromCheerioEle(firstContainer, "class")   
             

Tell the Puppeteer Helper to click on this element:

await ph.click(page, ch.getUniqueSelector(firstContainer));

Find an element from the DOM, carrying a specific text:

let divWithTxt = await ch.getElementByText(dom, "Hello World!")    

Will wait for an element to change it's value (div with a "popup" class to change it's style from display="inline" to display="none" ):

await ch.waitForSelectorToChangeAttValue(page, selector="div.popup", att="style", val="display: none;", checkEach=2000)

Will loop on a 'select' element children ('option' tags) and look for a given text.
Optionally: if the text exists, will select it.
NOTICE: if you want to select the option, you need to supply a puppeteer helper instance, a page instance, and toggle the selectIfExists to true:

let selected = await ch.isSelectHasValue(selectElement, "black", true, ph, page);
    

And a lot more!

Links

npm os-puppeteer-helper npm os-cheerio-helper

Licence

ISC

os-cheerio-helper-npm