0.4.5 • Published 6 years ago

page-grabber v0.4.5

Weekly downloads
5
License
ISC
Repository
github
Last release
6 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

6 years ago

0.4.4

6 years ago

0.4.3

6 years ago

0.4.2

7 years ago

0.4.1

7 years ago

0.4.0

7 years ago

0.3.27

7 years ago

0.3.26

7 years ago

0.3.25

7 years ago

0.3.24

7 years ago

0.3.23

7 years ago

0.3.22

7 years ago

0.3.21

7 years ago

0.3.20

7 years ago

0.3.19

7 years ago

0.3.18

7 years ago

0.3.17

7 years ago

0.3.16

7 years ago

0.3.15

7 years ago

0.3.14

7 years ago

0.3.13

7 years ago

0.3.12

7 years ago

0.3.11

7 years ago

0.3.9

7 years ago

0.3.8

7 years ago

0.3.7

7 years ago

0.3.6

7 years ago

0.3.5

8 years ago

0.2.5

8 years ago

0.2.4

8 years ago

0.2.3

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago