goose-parser
Multi environment web page parser
Last updated 7 months ago by redcode .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install goose-parser 
SYNC missed versions from official npm registry.

mr.Goose

goose-parser

CircleCI (all branches) Codecov Latest Stable Version Total Downloads NPM downloads

This tool moves routine crawling process to the new level. Now it's possible to parse a web page for a moment. All you need is to specify parsing rules based on css selectors. It's so simple as Goose can do it. This library allows to parse such data types as Grid, Collections, and Simple objects. Parser has support of pagination by extension goose-paginator. Also it offers you following features: actions to interact with the page and transforms to convert parsed data to friendly format.

Goose Starter Kit

Now it's easy to start with Goose, just try to use goose-starter-kit for it.

Key features

  • Declarative approach for definition of parsing rules, actions and transformations.
  • Multi environments to run parser on the browser, PhantomJS, Chrome, JsDOM and more.
  • Clear code with the latest features of ES6.
  • Clear and consistent API with promises all the way.
  • Improved Sizzle format of selectors.
  • Ajax and multi-pages parsing modes.
  • Docker Support.
  • It's easy extendable.

Installation

yarn add goose-parser goose-chrome-environment

Usage

const Parser = require('goose-parser');
const ChromeEnvironment = require('goose-chrome-environment');

const env = new ChromeEnvironment({
  url: 'https://www.google.com/search?q=goose-parser',
});

const parser = new Parser({ environment: env });

(async function () {
  try {
    const results = await parser.parse({
      actions: [
        {
          type: 'wait',
          timeout: 10 * 1000,
          scope: '.srg>.g',
          parentScope: 'body'
        }
      ],
      rules: {
        scope: '.srg>.g',
        collection: [[
          {
            name: 'url',
            scope: 'h3.r>a',
            attr: 'href',
          },
          {
            name: 'text',
            scope: 'h3.r>a',
          }
        ]]
      }
    });
    console.log(results);
  } catch (e) {
    console.log('Error occurred:');
    console.log(e.stack);
  }
})();

Environment

This is a special atmosphere where Parser has to be executed. The main purpose of an environment is to provide a method for evaluating JS on the page. Goose supports following environments:

  • PhantomJS (executes in NodeJS)
  • Chrome (executes in NodeJS)
  • JSDom (executes in NodeJS)
  • FireFox (coming soon)
  • Browser (executes in Browser)

Docker usage

For now it's available to run goose-parser as a docker service.

Params:

  • url - first param is an url to parser
  • Parsing rules [optional] - Rules to parse. It's optional, if --rules-file specified.

Options:

  • -e "DEBUG=*" - to enable debug mode and see all what happens inside the goose-parser. Reed more about debug here.
  • --rules-file - to specify rules file. Be aware that you need to mount a folder with rules as a volume to the docker container.

There are two options to run it:

Process parsing from the user input

docker run -it --rm -e "DEBUG=*,-puppeteer:*" redcode/goose-parser:chrome-1.1.3-parser-0.6.0\
    https://www.google.com/search?q=goose-parser\
    '{
      "actions": [
        {
          "type": "wait",
          "scope": ".g"
        }
      ],
      "rules": {
        "scope": ".g",
        "collection": [
          [
            {
              "scope": ".r>a h3",
              "name": "name"
            },
            {
              "scope": ".r>a:eq(0)",
              "name": "link",
              "attr": "href"
            }
          ]
        ]
      }
    }'

Process parsing from the mounted file with parsing rules

Create a file rules/rules.json which contains parser rules and run following command:

docker run -it --rm --volume="`pwd`/rules:/app/rules:ro" -e "DEBUG=*,-puppeteer:*" redcode/goose-parser:chrome-1.1.3-parser-0.6.0 --rules-file="/app/rules/rules.json" 'https://www.google.com/search?q=goose-parser'

Documentation

Based on the code you can find detailed documentation about actions and transformations

API reference - coming soon

Current Tags

  • 0.6.1                                ...           latest (7 months ago)

87 Versions

  • 0.6.1                                ...           7 months ago
  • 0.6.0                                ...           8 months ago
  • 0.5.2                                ...           a year ago
  • 0.5.1                                ...           a year ago
  • 0.5.0-beta.8                                ...           a year ago
  • 0.5.0-beta.7                                ...           a year ago
  • 0.5.0-beta.6                                ...           a year ago
  • 0.5.0-beta.5                                ...           a year ago
  • 0.5.0-beta.4                                ...           a year ago
  • 0.5.0-beta.3                                ...           2 years ago
  • 0.5.0-beta.2                                ...           2 years ago
  • 0.5.0-beta.1                                ...           2 years ago
  • 0.5.0-alpha.4                                ...           2 years ago
  • 0.5.0-alpha.3                                ...           2 years ago
  • 0.5.0-alpha.2                                ...           2 years ago
  • 0.5.0-alpha.1                                ...           2 years ago
  • 0.3.0-alpha.5                                ...           2 years ago
  • 0.3.0-alpha.4                                ...           2 years ago
  • 0.3.0-alpha.3                                ...           2 years ago
  • 0.3.0-alpha.2                                ...           2 years ago
  • 0.3.0-alpha.1                                ...           2 years ago
  • 0.3.0-alpha                                ...           2 years ago
  • 0.2.0-alpha.60                                ...           2 years ago
  • 0.2.0-alpha.58                                ...           2 years ago
  • 0.2.0-alpha.57                                ...           2 years ago
  • 0.2.0-alpha.56                                ...           2 years ago
  • 0.2.0-alpha.55                                ...           2 years ago
  • 0.2.0-alpha.54                                ...           3 years ago
  • 0.2.0-alpha.53                                ...           3 years ago
  • 0.2.0-alpha.52                                ...           3 years ago
  • 0.2.0-alpha.51                                ...           3 years ago
  • 0.2.0-alpha.50                                ...           3 years ago
  • 0.2.0-alpha.49                                ...           3 years ago
  • 0.2.0-alpha.48                                ...           3 years ago
  • 0.2.0-alpha.47                                ...           3 years ago
  • 0.2.0-alpha.46                                ...           3 years ago
  • 0.2.0-alpha.45                                ...           3 years ago
  • 0.2.0-alpha.44                                ...           3 years ago
  • 0.2.0-alpha.43                                ...           3 years ago
  • 0.2.0-alpha.42                                ...           3 years ago
  • 0.2.0-alpha.41                                ...           3 years ago
  • 0.2.0-alpha.40                                ...           3 years ago
  • 0.2.0-alpha.39                                ...           3 years ago
  • 0.2.0-alpha.38                                ...           3 years ago
  • 0.2.0-alpha.37                                ...           3 years ago
  • 0.2.0-alpha.36                                ...           3 years ago
  • 0.2.0-alpha.35                                ...           3 years ago
  • 0.2.0-alpha.34                                ...           3 years ago
  • 0.2.0-alpha.33                                ...           3 years ago
  • 0.2.0-alpha.32                                ...           4 years ago
  • 0.2.0-alpha.31                                ...           4 years ago
  • 0.2.0-alpha.30                                ...           4 years ago
  • 0.2.0-alpha.29                                ...           4 years ago
  • 0.2.0-alpha.28                                ...           4 years ago
  • 0.2.0-alpha.27                                ...           4 years ago
  • 0.2.0-alpha.26                                ...           4 years ago
  • 0.2.0-alpha.25                                ...           4 years ago
  • 0.2.0-alpha.24                                ...           4 years ago
  • 0.2.0-alpha.23                                ...           4 years ago
  • 0.2.0-alpha.22                                ...           4 years ago
  • 0.2.0-alpha.21                                ...           4 years ago
  • 0.2.0-alpha.20                                ...           4 years ago
  • 0.2.0-alpha.19                                ...           4 years ago
  • 0.2.0-alpha.18                                ...           4 years ago
  • 0.2.0-alpha.17                                ...           4 years ago
  • 0.2.0-alpha.16                                ...           4 years ago
  • 0.2.0-alpha.15                                ...           4 years ago
  • 0.2.0-alpha.14                                ...           4 years ago
  • 0.2.0-alpha.13                                ...           4 years ago
  • 0.2.0-alpha.12                                ...           4 years ago
  • 0.2.0-alpha.11                                ...           4 years ago
  • 0.2.0-alpha.10                                ...           4 years ago
  • 0.2.0-alpha.9                                ...           4 years ago
  • 0.2.0-alpha.8                                ...           4 years ago
  • 0.2.0-alpha.7                                ...           4 years ago
  • 0.2.0-alpha.6                                ...           4 years ago
  • 0.2.0-alpha.5                                ...           4 years ago
  • 0.2.0-alpha.4                                ...           4 years ago
  • 0.2.0-alpha.3                                ...           4 years ago
  • 0.2.0-alpha2                                ...           4 years ago
  • 0.2.0-alpha                                ...           4 years ago
  • 0.1.6                                ...           4 years ago
  • 0.1.5                                ...           4 years ago
  • 0.1.4                                ...           4 years ago
  • 0.1.3                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
Maintainers (2)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 4
Dependencies (8)
Dev Dependencies (0)
None

Copyright 2014 - 2017 © taobao.org |