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

canner-extract

v0.2.3

Published

Canner prompt cli tool for extracting data from html

Downloads

5

Readme

canner-extract

A html extractor for canner

Install

npm install -g canner-extract

Usage

  Usage: canner-extract <html_file, default value: "index.html">

  Options:

    -h, --help     output usage information
    -V, --version  output the version number
    -m, --manually  manually naming text node

Auto-extracting

extracting a html file to canner.json and layout automatically.

canner-extract index.html

Before

A sample html:

<html>
  <title>
  </title>

  <body>
    This is text 1

    <p> This is text 2 </p>

    <span> This is text 3 </span>

    <p> This is text 4 <span> This is text 5 </span> </p>

    This is text 6
  </body>

</html>

AFTER extract-html

test_after.html:

<html>

<head>
    <title>
    </title>

</head>

<body>{{0}}
    <p>{{1}}</p>

    <span>{{2}}</span>

    <p>{{3}}<span>{{4}}</span> </p>{{5}}</body>

</html>

test_output.json:

{
    "0": "This is text 1",
    "1": "This is text 2",
    "2": "This is text 3",
    "3": "This is text 4",
    "4": "This is text 5",
    "5": "This is text 6"
}

Manually-extracting

extracting a html file to canner.json and layout manually.

canner-extract -m index.html

This will prompt some messages for you to fill in, which will set the values in canner.json.

Preview

preview

Result

canner.json:

{
    "layout": "layout.hbs",
    "filename": "output.html",
    "data": {
        "name": "Willis Corto",
        "side-title1": "I got reprogrammed by a rogue AI",
        "side-title2": "and now I'm totally cray",
        "side-tab1": "About",
        "side-tab2": "Things I Can Do",
        "side-tab3": "A Few Accomplishments",
        "side-tab4": "Contact",
        "side-twitter": "Twitter",
        "side-facebook": "Facebook",
        "side-instagram": "Instagram",
        "side-github": "Github",
        "side-email": "Email",
        "main-title1": "Read Only",
        "main-title2": "Things I Can Do",
        "main-subtitle1": "Just an incredibly simple responsive site",
        "main-subtitle2": "template freebie by",
        "main-content1": "Faucibus sed lobortis aliquam lorem blandit. Lorem eu nunc metus col. Commodo id in arcu ante lorem ipsum sed accumsan erat praesent faucibus commodo ac mi lacus
        ....
        ...
    }
}

layout.hbs:

...
...

<body>
    <div id="wrapper">

        <!-- Header -->
        <section id="header" class="skel-layers-fixed">
            <header>
                <span class="image avatar"><img src="images/avatar.jpg" alt=""></span>
                <h1 id="logo"><a href="#">{{name}}</a></h1>
                <p>{{side-title1}}
                    <br>{{side-title2}}</p>
            </header>
            <nav id="nav">
                <ul>
                    <li><a href="#one" class="active">{{side-tab1}}</a>
                    </li>
                    <li><a href="#two">{{side-tab2}}</a>
                    </li>
                    <li><a href="#three">{{side-tab3}}</a>
                    </li>
                    <li><a href="#four">{{side-tab4}}</a>
                    </li>
                </ul>
            </nav>

...

API

autoParse(html path, opt)

  • html path: should be the absolute path to your html file.

return a promise

canner_extract.autoParse(html, opt)
  .then(function(result) {
    // console.log(result.html);  
    // console.log(result.json);  
  });

manuallyParse(html, opt)

  • html path: should be the absolute path to your html file.

return a promise

canner_extract.autoParse(html, opt)
  .then(function(result) {
    // console.log(result.html);  
    // console.log(result.json);  
  });

Example

https://github.com/Canner/readonly-can

License

MIT