Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
crawler-template-manual
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zhangkai
crawler-template-manual
Commits
647562c9
Commit
647562c9
authored
Jan 02, 2019
by
Jinhao Chen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update README.md
parent
6f439aac
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
446 additions
and
0 deletions
+446
-0
README.md
+446
-0
No files found.
README.md
View file @
647562c9
# 知微数据可视化爬虫平台
项目主页: http://crawler.zhiweidata.com
>## 1 配置简介
>>### 1.1 解析器简介
>>> 目前解析器一共有6种解析器,分别是:Appender 解析器,JSONPath 解析器,Jsoup 解析器,XPath 解析器,Regex 解析器,Time 解析器,Helper 解析器,Assert 解析器,AssertFilter 解析器,未来可能会持续增加,解析器格式如下:
>>> ```
{
"parserName": "jsoup",
"parsingType": "attr",
"command": "div
[
class=result
]
>a",
"attrName": "href"
}
>>> ```
>>> |key|value|
>>> |:---|:---|
>>> |parseName|解析器名称,即上述解析器名称|
>>> |parsingType|解析器类型,每种不同的解析器有不同的解析类型|
>>> |command|解析器命令|
>>> |attrName|解析器附加字段,此字段可缺省,仅在需要的时候使用|
>>>#### 1.1.1 Appender 解析器
>>>> Appender 解析器支持的 parsingType 有:overwrite,prefix,suffix,同时支持宏命令调用
>>>>##### overwrite:顾名思义即重写,根据 command 内容进行重写,一般用于新建变量,例:
>>>> ```
"field":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "hello"
}
]
>>>> ```
>>>> 输出结果: field = hello
>>>>##### prefix:即在输入数据的左边即开头追加字符串或宏命令
>>>>##### suffix: 即在输入数据的右边即末尾追加字符串或宏命令
>>>> ```
"field":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "hello"
},
{
"parserName": "appender",
"parsingType": "prefix",
"command": "AAA"
},
{
"parserName": "appender",
"parsingType": "suffix",
"command": "BBB"
}
]
>>>> ```
>>>> 输出结果: field = AAAhelloBBB
>>>>#### 使用宏命令
>>>> |宏|作用|
>>>> |:---|:---|
>>>> |$pre|表示引用与上下文有关的属性|
>>>> |$pre.field1|引用上一层的 field1 字段的值|
>>>> |$pre.$pre.field1|引用上一层的上一层的 field1 字段的值,可写多层|
>>>> |$self|表示引用页面的属性,目前仅支持 $self.url 一个属性的调用|
>>>> |$self.url|当前页面的 url,$self 意为页面本身的属性,目前仅有 url 一个属性|
>>>> |$pre.$self.url|上一层页面的自身的 url|
>>>> |$cur|表示当前引用当前层的其他属性,被引用的属性必须在被引用之前解析|
>>>> |$cur.field1|表示引用当前层的 field1 属性|
>>>> |$origin|表示引用输入到当前解析器的之前的数据,也支持类似于 $pre.$origin 形式的调用|
>>>> |$macro|表示使用宏命令,目前仅支持 $macro.$timeformat 与 $macro.$timestamp 两个宏调用|
>>>> |$macro.$timestamp|输出当前时间戳(毫秒级)|
>>>> |$macro.$timestamp.s|输出当前时间戳(秒级)|
>>>> |$macro.$timestamp.ms|输出当前时间戳(毫秒级)|
>>>> |$macro.$timeformat.yyyy-MM-dd|当前时间的格式化形式,yyyy-MM-dd 为自定义时间 pattern|
>>>> 例:
>>>> ```
"url":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "http://zhiweidata.com/"
},
{
"parserName": "appender",
"parsingType": "suffix",
"command": "$macro.$timestamp"
},
{
"parserName": "appender",
"parsingType": "suffix",
"command": "/"
},
{
"parserName": "appender",
"parsingType": "suffix",
"command": "$macro.$timeformat.yyyyMMdd"
}
]
>>>> ```
>>>> 输出结果: url = http://zhiweidata.com/1535614813099/20180830
>>>#### 1.1.2 Jsoup 解析器
>>>> Jsoup 解析器支持的 parsingType 有:attrFirst, attrAll,textFirst, textAll,htmlFirst, htmlAll
>>>> command 支持以 | 隔开的多条命令,会自动合并结果集
>>>>##### attrFrist:对应 Jsoup 方法 attr() 即取第一个属性值,需要用到 attrName 字段,command 对应 Jsoup 的 select() 方法
>>>>##### attrAll:对应 Jsoup 方法 attr() 即取所有属性值,需要用到 attrName 字段,command 对应 Jsoup 的 select() 方法,例:
>>>>```
"url":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "
<a
href=
http://zhiweidata.com
>
知微数据
<a>
"
},
{
"parserName": "jsoup",
"parsingType": "attrAll",
"command": "a",
"attrName": "href"
}
]
>>>>```
>>>> 即取 <a> 标签的 href 属性,结果为:url = http://zhiweidata.com
>>>>##### textFirst:对应 Jsoup 方法 text() 即取第一个文本值,command 对应 Jsoup 的 select() 方法:
>>>>##### textAll:对应 Jsoup 方法 text() 即取所有文本值,command 对应 Jsoup 的 select() 方法,例:
>>>>```
"text":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "
<a
href=
http://zhiweidata.com
>
知微数据
<a>
"
},
{
"parserName": "jsoup",
"parsingType": "textAll",
"command": "a"
}
]
>>>>```
>>>> 即取 <a> 标签的文本属性,结果为:text = 知微数据
>>>>##### htmlFirst:对应 Jsoup 方法 text() 即取第一个 html 代码,command 对应 Jsoup 的 select() 方法
>>>>##### htmlAll:对应 Jsoup 方法 text() 即取所有 html 代码,command 对应 Jsoup 的 select() 方法,例
>>>>```
"html":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "
<a
href=
http://zhiweidata.com
>
知微数据
<a>
"
},
{
"parserName": "jsoup",
"parsingType": "htmlAll",
"command": "
*
"
}
]
>>>>```
>>>> 即取 <a> 标签的 html 代码,结果为:html = <a href="http://zhiweidata.com">知微数据<a>
>>>#### 1.1.3 XPath 解析器
>>>> XPath 解析器支持的 parsingType 有:attr,text,html,使用方法与 Jsoup 解析器一致,这里不再赘述
>>>#### 1.1.4 JSONPath 解析器
>>>> JSONPath 解析器支持的 parsingType 只有:jsonFirst 与 jsonAll,其中 command 为 JSONPath 语法
>>>>##### jsonFirst:取 jsonpath 执行结果的第一个值
>>>>##### jsonAll:取 jsonpath 执行结果的所有值
>>>>```
"last":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "{'number':
[
1, 1, 2, 3, 5
]
}"
},
{
"parserName": "jsonpath",
"parsingType": "jsonAll",
"command": "$.number
[
-1
]
"
}
]
>>>>```
>>>> 结果为 last = 5
>>>#### 1.1.5 Regex 解析器
>>>> Regex 解析器支持的 parsingType 有:matchFirst, matchAll,replaceFirst, replaceAll 四种,其中 command 为 正则表达式语句
>>>>##### matchFirst:选取输入中所有符合正则表达式的字符串序列的第一个结果
>>>>##### matchAll:选取输入中所有符合正则表达式的字符串序列的所有结果,例:
>>>>```
"string":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "知微数据"
},
{
"parserName": "regex",
"parsingType": "matchAll",
"command": "微"
}
]
>>>>```
>>>> 结果为 string = 微
>>>>##### replaceFirst:将所有符合正则表达式的字符串序列的第一个序列替换为 attrName 属性中的值,如果缺省 attrName 则将所有符合正则表达式的字符串序列替换为空
>>>>##### replaceAll:将所有符合正则表达式的字符串序列的所有序列替换为 attrName 属性中的值,如果缺省 attrName 则将所有符合正则表达式的字符串序列替换为空,例:
>>>>```
"string":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "知微数据"
},
{
"parserName": "regex",
"parsingType": "replaceAll",
"command": "数据"
}
],
"string":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "知微数据"
},
{
"parserName": "regex",
"parsingType": "replaceAll",
"command": "数据",
"attrName": ""
}
]
>>>>```
>>>> 如上所示两组执行结果一致,结果为 string = 知微
>>>>```
"string":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "知微数据"
},
{
"parserName": "regex",
"parsingType": "replaceAll",
"command": "数据",
"attrName": "data"
}
]
>>>>```
>>>> 结果为 string = 知微data
>>>#### 1.1.6 Time 解析器
>>>> Regex 解析器支持的 parsingType 有:timestamp,before,format, auto 四种,其中 command 为时间 pattern,一般无特殊情况,请默认使用 auto
>>>> 默认支持自动解析 UTC GMT 等格式的时间戳
>>>> command 支持以 | 分隔的多个命令,直到匹配到为止
>>>>##### auto:会依次尝试 timestamp,before,format 三种解析,例:
>>>>```
"time":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "1秒前"
},
{
"parserName": "time",
"parsingType": "auto"
}
]
>>>>```
>>>>```
"time":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "2015年6月30日"
},
{
"parserName": "time",
"parsingType": "auto"
"command": "yyyy MM dd"
}
]
>>>>```
>>>>```
"time":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "2015年6月30日"
},
{
"parserName": "time",
"parsingType": "auto"
"command": "yyyy MM dd|yyyyMMdd"
}
]
>>>>```
>>>>```
"time":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "2015 jun 30"
},
{
"parserName": "time",
"parsingType": "auto"
"command": "yyyy MM dd|yyyyMMdd"
}
]
>>>>```
>>>>```
"time":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "15年6月30日"
},
{
"parserName": "time",
"parsingType": "auto"
"command": "yy MM dd"
}
]
>>>>```
>>>> 上述规则支持解析2015年6月30日或20150630的形式或包含英文日期格式
>>>#### 1.1.7 Helper 解析器
>>>> Helper 解析器支持的 parsingType 有:fixurl,javascript,articleExtract,其中 command 支持所有宏(一般用 $self.url 或 $pre.self.url)与普通字符串
>>>>##### fixurl:根据上次访问的 URL,结合输入(绝对或相对 URL),生成一个新的绝对 URL,例:
>>>>```
"url":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "../index.html"
},
{
"parserName": "helper",
"parsingType": "fixurl"
"command": "http://zhiweidata.com/service/"
}
]
>>>>```
>>>>##### javascript:运行 js 脚本,其中请使用 $input 来获取上文传来的数据,例如:
>>>>```
"test":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "123"
},
{
"parserName": "helper",
"parsingType": "javascript"
"command": "return $input - 1;"
}
]
>>>>```
>>>> 结果为 test = 122
>>>>##### articleExtract:讲上文传递过来的数据进行正文提取,例如:
>>>>```
"text":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "
<p><em>
知微
<em>
数据
</p>
"
},
{
"parserName": "helper",
"parsingType": "articleExtract"
}
]
>>>>```
>>>> 结果为 text = 知微数据
>>>#### 1.1.8 Assert 解析器
>>>> Assert 解析器支持的 parsingType 有:hoursLimit,minutesLimit,contains,matches,notEmpty 六种解析类型,通过 Assert 解析器,符合条件的数据最终会被保留,这里请注意与 AssertFilter 相反
>>>>##### hoursLimit、minutesLimit:针对时间进行小时级、分钟级限制,例:
>>>>```
"time":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "1秒前"
},
{
"parserName": "time",
"parsingType": "auto"
},
{
"parserName": "assert",
"parsingType": "hoursLimit",
"command": "1"
}
]
>>>>```
>>>##### contains:判断输入是否包含某字符串序列,例:
>>>>```
"content":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "hello, zhiwei"
},
{
"parserName": "assert",
"parsingType": "contains",
"command": "zhiwei"
}
]
>>>>```
>>>##### matches:判断输入是否能完全匹配正则表达式,例:
>>>>```
"content":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "hello, zhiwei"
},
{
"parserName": "assert",
"parsingType": "matches",
"command": ".
*?,.*
"
}
]
>>>>```
>>>##### empty:判断输入是否是空字符串或者仅含有空格制表符换行符等无文本字符串,例:
>>>>```
"content":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "hello, zhiwei"
},
{
"parserName": "assert",
"parsingType": "empty"
}
]
>>>>```
>>>##### notEmpty:判断输入是否不是空字符串或者仅含有空格制表符换行符等无文本字符串,例:
>>>>```
"content":
[
{
"parserName": "appender",
"parsingType": "overwrite",
"command": "hello, zhiwei"
},
{
"parserName": "assert",
"parsingType": "notEmpty"
}
]
>>>>```
>>>#### 1.1.9 AssertFilter 解析器
>>>> AssertFilter 解析器支持的 parsingType 有:hoursLimit,minutesLimit,contains,matches,notEmpty 六种解析类型,通过 Assert 解析器,符合条件的数据最终将会被过滤掉,这里注意与 Assert 解析器相反
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment