Code Monkey home page Code Monkey logo

fast-wasm-scraper's Introduction

fast-wasm-scraper

Continuous integration

A fast alternative for JavaScript-based scraping tools, intended for both frontend and backend. fast-wasm-scraper is practically a wrapper for scraper (intended for parsing HTML and querying with CSS selectors) -- which compiles to WebAssembly.

Installation

$ yarn add fast-wasm-scraper

Examples

Loading

const { Document } = require('fast-wasm-scraper');
const doc = new Document('<html>Hello world!</html>');

doc.root.inner_html;
// => <html>Hello world!</html>

Querying

const { Document } = require('fast-wasm-scraper');
const html = `
<html>
  <body>
    <div>
      <ul>
        <li>One</li>
        <li>Two</li>
        <li>Three</li>
      </ul>
    </div>
  </body>
</html>
`;
const doc = new Document(html);

doc.root.query('li');
// => [
//      Element { name: 'li', inner_html: 'One',   ... },
//      Element { name: 'li', inner_html: 'Two',   ... },
//      Element { name: 'li', inner_html: 'Three', ... },
//    ]

Types

Document

property type Description
constructor (html: string) => Document Takes the raw html as a string and returns a new Document object
root Element Returns the root element of the Document

Element

property type Description
name string Returns the name of the element as a string, ex: 'div'
html string Returns a string representation of this Element and it's descendants
inner_html string Returns the inner content of this Element as a string
attributes Map<string, string> Returns the attributes as a Map<string, string>
query (query_str: string) => Array<Element> Returns an array of Elements from the resulting query
text () => Array<string> Returns an array of strings from descending text nodes

Benchmark

fast-wasm-scraper cheerio JsDOM
Runtime WebAssembly (from Rust) JavaScript JavaScript
Parsing, and querying with li, for a document with 100 list items
Sample size (#) 87 74 52
Speed (ops/s) 539 (+/- 1.37%) 318 (+/- 4.75%) 38.2 (+/- 11.25%)
Speedup 1.69x compared to cheerio, and 14x to JsDOM - -

This benchmark was conducted on a rather modest dual core CPU and Node.js v.12.20.0. You can also run the benchmarks locally by cloning the GitHub repository.

fast-wasm-scraper's People

Contributors

julleboi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

480 jade2290 andrwj

fast-wasm-scraper's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.