isomorphic-parse
v0.0.3
Published
DOM parsing for both node & browserify. A wrapped library of jquery & cheerio.
Readme
isomorphic-parse
DOM parsing for both node & browserify. A wrapped library of jquery & cheerio.
Installation
NPM
npm install --save isomorphic-parseWebpack config
If you're using webpack, you would also need the following setup from cheerio build issue.
install json-loader
npm install --save-dev json-loaderGo to your webpack config and make sure to use the "json-loader" and configure that "cheerio/package" is resolved with the "json-loader".
module: {
loaders: [
{
test: /cheerio\/package$/,
loader: 'json'
},
]
}Usage
const $ = require('isomorphic-parse')
fetch(`some url`).then(r => r.text()).then(response => {
var doc = $(response)
console.log(doc.find('ul a').attr('href'))
})Note that in node environment, I map cheerio constructor function to find like this:
// index-node.js
var cheerio = require('cheerio');
cheerio.find = cheerio;
module.exports = cheerio;Now in cheerio, we can use find method in jquery style, but it should be differed from jquery global query style, $(selector) .
LISENCE
MIT
