# bquery

> bquery is a useful node module to fetch web page, which use css selector to fetch and structure this html page content.

Latest version **0.4.0** (published 2017-03-24) · BSD license · 0 weekly downloads

## Install

```sh
npm install bquery
pnpm add bquery
yarn add bquery
bun add bquery
```

Provides the command `noodle`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2017-03-24 |
| First published | 2014-05-01 |
| Weekly downloads | 0 |
| License | BSD |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 16 |
| Known vulnerabilities | 0 (+8 in 3 direct dependencies) |
| Install scripts | no |
| Author | BeyondLink |
| Maintainers | rickjose |
| Keywords | scraper, proxy, cross-domain, cross domain, selectors, JSONSelect, json, html, rate limit |

## Links

- npm: https://www.npmjs.com/package/bquery
- npm.io page: https://npm.io/package/bquery

## Dependencies (16)

- [q](https://npm.io/package/q.md) 0.8.9
- [chai](https://npm.io/package/chai.md) 1.4.2
- [mocha](https://npm.io/package/mocha.md) 1.7.4
- [urijs](https://npm.io/package/urijs.md) *
- [colors](https://npm.io/package/colors.md) 0.6.0-1
- [moment](https://npm.io/package/moment.md) 1.7.2
- [cheerio](https://npm.io/package/cheerio.md) 0.14.0
- [connect](https://npm.io/package/connect.md) ~2.3.5
- [request](https://npm.io/package/request.md) 2.11.4
- [req-fast](https://npm.io/package/req-fast.md) *
- [xml2json](https://npm.io/package/xml2json.md) 0.9.0
- [JSONSelect](https://npm.io/package/JSONSelect.md) 0.4.0
- [feedparser](https://npm.io/package/feedparser.md) 0.10.7
- [underscore](https://npm.io/package/underscore.md) *
- [html-to-text](https://npm.io/package/html-to-text.md) 1.3.0
- [connect-ratelimit](https://npm.io/package/connect-ratelimit.md) 0.0.5

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.4.0 (latest) — 2017-03-24
- 0.0.2 (0.0.2) — 2014-11-04
- 0.3.0 — 2017-03-22
- 0.2.3 — 2016-05-16
- 0.2.2 — 2016-05-16
- 0.2.1 — 2016-03-09
- 0.2.0 — 2016-03-09
- 0.1.0 — 2016-01-10
- 0.0.4 — 2016-01-10
- 0.0.3 — 2015-07-20
- 0.0.1 — 2014-05-01

## README

# bquery

Quick , simple and elegant way to fetch a web documents and structure it.

## Installation

Latest release:

    $ npm install bquery


```js
var buquery = require("buqery");
bquery.query({
  "url": "https://github.com/",
  "selector": "ul.header-nav.left>li",
  "extract": {
    "title":{},
    "url": {
      "selector": "a",
      "extract": "href"
    }
  }
}).then(function(docs){
  console.log(docs);
  //=> {"results":[{"result":[{"title":"Explore","url":"https://github.com/explore"},{"title":"Features","url":"https://github.com/features"},{"title":"Enterprise","url":"https://enterprise.github.com/"},{"title":"Blog","url":"https://github.com/blog"}]}]}
})
```


## Options
bquery can sutomatic recognition the web document charset, but special circumstances you can also set docuemnt's charset.

```js
var buquery = require("buqery");
bquery.query({
  "url": "https://github.com/",
  "selector": "ul.header-nav.left>li",
  "charset": "utf-8",
  "extract": {
    "title":{},
    "url": {
      "selector": "a",
      "extract": "href"
    }
  }
}).then(function(docs){
  console.log(docs);
})
```


You can also set the timeout period for the request.
```js
bquery.query({
  "url": "https://github.com/",
  "selector": "ul.header-nav.left>li>a",
  "timeout": 3000
});
```


Sometimes you need to modify the page content link css, javascript or other content before you fetch the docuemnt content. you can use "preSelect" option.
```js
bquery.query({
  "url": "https://github.com/",
  "selector": "ul.header-nav.left>li",
  "preSelect": function($){   //=> $ is a cheerio object, you can do any operate wich base on cheerio
    $("ul.header-nav.left>li").each(function(i, elem){
      if($("a", elem).text() == "Explore"){
        $(elem).remove()
      }
    });
  },
  "extract": {
    "title":{},
    "url": {
      "selector": "a",
      "extract": "href"
    }
  }
}).then(function(docs){
  console.log(docs); 
  //=>[
  //=>  { title: 'Features', url: 'https://github.com/features' },
  //=>  { title: 'Enterprise', url: 'https://enterprise.github.com/' },
  //=>  { title: 'Blog', url: 'https://github.com/blog' } 
  //=>]
})
```


you can also use callback to modify selected attribute
```js
{
  "url": "https://github.com/",
  "selector": "ul.header-nav.left>li",
  "extract": {
    "title":{
      "extract": "text",
      "callback": function(txt){
        return "foo_" + txt;
      }
    },
    "url": {
      "selector": "a",
      "extract": "href"
    }
  }
}
```

---
_Source: https://npm.io/package/bquery · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
