c-resolver a tool for crawler
Installation
npm install c-resolver
example
test.html
get something you need from h1Text l1 l2 l3 l4
- get attribute value
- get class name from h1const define ="name": "item""type": "item""process": "processItem""match": "/""filter": "div""define":"name": "name""type": "att""att": "class""match": "./""process": "[COMMON_STR_PROCESS]""filter": "h1";{this { //handle item befor outputreturn item;};return this;}let res = ;/*** res = {item:{name:"h1Class"}}* /
- get a list from ul->liconst define ="name": "item""type": "item""process": "processItem""match": "/""filter": "ul""define":"name": "list""match": "./""type": "list""filter": "li""process": "processList""define":"name": "name""type": "text""process": "[COMMON_STR_PROCESS]";{return item;};{return list;}let res = ;/*** res = {item:[{"name":"l1"},{"name":"l2"},{"name":"l3"},{"name":"l4"}]}* /
- get a list from ul->li
- get class name from h1
-there are more example
how define define&process
- "name": "key", //outut obejct key
- "type": "valueType", //value type:
- item: output value is a object,
- lis: output value is a array(collection)
- text: output value is a string
- att: output value is a string(if type is att, should define att value )
- "att": "attName", //element attribute name
- "process": "processItem", //a function excute before output with param
- "match": "/", // cheerio will find element by selector(filter) in the following element object
- '/' is root element obejct from cheerio.load(root element html)
- "./" is father element object
- "filter": "div", // element selector
process
must be a function and return output value you want