Json Web Crawler
Use JSON to list all elements (with css 3 and jquery selector) that you want to crawl.
Only run in node >= 4.0
run the two scripts (kickstarter & steam) in terminal to see what happen.
Usage
npm i json-web-crawler --save
var Crawl = require('json-web-crawl');
Crawl('HTML content', your json setting)
.then(console.log)
.catch(console.log);
Different from 0.0.6
You can compare it in demo
limit
, range
, focus
and ignore
combine to listOption
keys
rename to crawl
- no
name
key in crawl
- no
use
key, only process
Variables
It's messy, I know.
var setting = {
pageNotFound: [{
elem: '.error-msg',
get: 'text',
check: ['equal', '404']
}],
type: 'content',
container: '.container',
type: 'list',
container: 'li.search-result',
listOption: ['limit', 10],
crawl: {
keyName: {
elem: '.element1:eq(0)',
noChild: true,
outOfContainer: true,
get: 'text',
process: [
['match', /regex here/, number],
['split', ',', number],
['replace', 'one', 'two'],
['substring', 0, 3],
['prepend', 'text'],
['append', 'text'],
['indexOf', 'text']
['independent function'],
]
},
keyName2: {
elem: 'table tbody thead',
collect: {
elems: [{
elem: 'tr:nth-child(1)',
get: 'text',
}, {
elem: 'tr:nth-child(2)',
get: 'num',
}, {
get: 'href'
}],
combineWith: ', '
}
},
keyName3: {
elem: 'table tbody tr',
collect: {
loop: true,
get: 'text',
combineWith: ', '
}
}
}
};
The MIT License (MIT)
Copyright (c) 2015 Knovour Zheng
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.