0.4.5 • Published 8 years ago

page-grabber v0.4.5

Weekly downloads
5
License
ISC
Repository
github
Last release
8 years ago

page-grabber

Util for grab data from web-page

NPM version Build Status Dependency Status Coverage percentage experimental

Install

npm install page-grabber --save

or 

yarn add page-grabber

Usage

    import { JSDOM } from "jsdom";
    import createGrabber, { attr$, html, sel$, text } from "page-grabber";

    const h = `
        <div id="div1">
            <ul>
                <li><a href="link1">Title1</a><span><b>Content1</b></span></li>
                <li><a href="link2">Titl2</a><span><b>Content2</b></span></li>
            </ul>
        </div>
    `;
    const window = new JSDOM(h).window;
    const grabber = createGrabber(window);
    const res = grabber.grab(sel$("#div1", {
        items: sel$("ul>li", [{
            title: sel$("a", text()),
            link: sel$("a", attr$("href")),
            content: sel$("span", html()),
        }]),
    }));
    for (const item of res.items) {
        console.log("title: ", item.title, "content: " + item.content);
        // title:  Title1 content: <b>Content1</b>
        // title:  Titl2 content: <b>Content2</b>
    }

API

attr(name: string) => string | null - get attribute by name
attr$(name: string) => string - get attribute by name with check for non-empty

Test

npm install
npm test
0.4.5

8 years ago

0.4.4

8 years ago

0.4.3

8 years ago

0.4.2

9 years ago

0.4.1

9 years ago

0.4.0

9 years ago

0.3.27

9 years ago

0.3.26

9 years ago

0.3.25

9 years ago

0.3.24

9 years ago

0.3.23

9 years ago

0.3.22

9 years ago

0.3.21

9 years ago

0.3.20

9 years ago

0.3.19

9 years ago

0.3.18

9 years ago

0.3.17

9 years ago

0.3.16

9 years ago

0.3.15

9 years ago

0.3.14

9 years ago

0.3.13

9 years ago

0.3.12

9 years ago

0.3.11

9 years ago

0.3.9

9 years ago

0.3.8

9 years ago

0.3.7

9 years ago

0.3.6

9 years ago

0.3.5

9 years ago

0.2.5

9 years ago

0.2.4

9 years ago

0.2.3

9 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago