public class CrawlerBuilder extends Object
Modifier and Type | Method and Description |
---|---|
CrawlerBuilder |
addExtractRule(ExtractRule extractRule)
增加内容提取规则
|
CrawlerBuilder |
addExtractRule(String key,
ExtractFieldRule fieldExtractRule)
根据内容提取规则的编码增加该内容提取规则的提取规则
|
CrawlerBuilder |
addExtractRules(List<ExtractRule> list)
增加内容提取规则
|
CrawlerBuilder |
addFieldExtractRules(String key,
List<ExtractFieldRule> list)
根据内容提取规则的编码增加该内容提取规则的提取规则
|
CrawlerBuilder |
addHeader(HeaderRule headerRule)
增加一组请求头参数
|
CrawlerBuilder |
addHeaders(List<HeaderRule> list)
增加一组请求头参数
|
CrawlerBuilder |
addLinkRule(MatcherRule linkRule)
增加链接提取规则
|
CrawlerBuilder |
addLinkRules(Set<MatcherRule> linkRules)
增加链接提取规则
|
CrawlerRule |
build()
构建一个风铃虫规则
|
String |
cacheControl()
获取网页缓存策略
默认为 max-age=0 |
CrawlerBuilder |
cacheControl(String cacheControl)
设置网页缓存策略
默认为 max-age=0 |
boolean |
circularRedirectsAllowed()
获取是否应允许循环重定向
|
CrawlerBuilder |
circularRedirectsAllowed(boolean circularRedirectsAllowed)
设置是否应允许循环重定向
|
int |
connectTimeout()
获取确定连接建立之前的超时时间(以毫秒为单位)
|
CrawlerBuilder |
connectTimeout(int connectTimeout)
设置确定连接建立之前的超时时间(以毫秒为单位)
|
ContentRule |
content()
获取内容页地址规则
|
CrawlerBuilder |
content(ContentRule content)
设置内容解析规则
|
boolean |
contentCompressionEnabled()
是否是否请求目标服务器压缩内容
|
CrawlerBuilder |
contentCompressionEnabled(boolean contentCompressionEnabled)
设置是否请求目标服务器压缩内容
|
MatcherRule |
contentPageRule()
获取内容页地址规则
多个规则之间用半角逗号隔开 |
CrawlerBuilder |
contentPageRule(MatcherRule contentPageRule)
设置内容页地址规则
多个规则之间用半角逗号隔开 |
String |
cookieSpec()
获取确定用于HTTP状态管理的cookie规范的名称
|
CrawlerBuilder |
cookieSpec(String cookieSpec)
设置 确定用于HTTP状态管理的cookie规范的名称
|
String |
cookieValue()
获取请求时携带cookie信息
此值为空时表示由内核智能处理 |
CrawlerBuilder |
cookieValue(String cookieValue)
设置请求时携带cookie信息
|
Crawler |
creatCrawler()
创建一个风铃虫简单实例
|
static CrawlerBuilder |
create()
创建一个默认风铃虫规则构建器
|
static CrawlerBuilder |
create(CrawlerRule crawlerRule)
根据已有规则 创建一个默认风铃虫规则构建器
|
ExtractRule |
extractRule(String key)
根据内容提取规则的编码获取 内容提取规则
|
List<ExtractRule> |
extractRules()
获取所有的内容提取规则
|
String |
failureMark()
获取失败标志
下载内容里包含此值时表示被服务器拦截,使用正则表达式,如果为空则不进行此校验 |
CrawlerBuilder |
failureMark(String failureMark)
设置失败标志
下载内容里包含此值时表示被服务器拦截,使用正则表达式,如果为空则不进行此校验 |
List<ExtractFieldRule> |
fieldExtractRule(String key)
根据内容提取规则的编码获取该内容提取规则的提取规则
|
List<HeaderRule> |
headers()
获取所有的请求头参数
|
int |
interceptCount()
获取拦截次数阀域值
连续多次在下载内容中获取到失败标识时的重试此次,超过此次数会关闭该风铃虫实例,默认为5 |
CrawlerBuilder |
interceptCount(int interceptCount)
设置拦截次数阀域值
连续多次在下载内容中获取到失败标识时的重试此次,超过此次数会关闭该风铃虫实例,默认为5 |
long |
interval()
获取每次请求的间隔时间,单位为毫秒,间隔时间为0到该值得两倍之间的一个随机数
防止因频繁请求而导致服务器封杀 默认时间为10000毫秒(10秒) |
CrawlerBuilder |
interval(long intervalInSeconds)
设置每次请求的间隔时间,单位为毫秒,间隔时间为0到该值得两倍之间的一个随机数
防止因频繁请求而导致服务器封杀, 默认时间为10000毫秒(10秒) |
LinkRule |
link()
获取链接解析规则
|
CrawlerBuilder |
link(LinkRule link)
设置链接解析规则
|
Set<MatcherRule> |
linkRules()
获取链接提取规则
|
Boolean |
matcherCaseSensitive()
获取匹配时是否大小写敏感
|
CrawlerBuilder |
matcherCaseSensitive(Boolean matcherCaseSensitive)
设置匹配时是否大小写敏感
|
Boolean |
matcherFuzzy()
匹配时是否为模糊匹配
|
CrawlerBuilder |
matcherFuzzy(Boolean matcherFuzzy)
设置匹配时是否为模糊匹配
|
Boolean |
matcherMode()
获取匹配模式
|
CrawlerBuilder |
matcherMode(Boolean matcherMode)
设置匹配模式
|
String |
matcherPattern()
获取 内容匹配参数
|
CrawlerBuilder |
matcherPattern(String matcherPattern)
设置内容匹配参数
|
String |
matcherTarget()
获取期待匹配值
|
CrawlerBuilder |
matcherTarget(String matcherTarget)
设置 期待匹配值
|
Type |
matcherType()
获取内容匹配类型
|
CrawlerBuilder |
matcherType(Type matcherType)
设置内容匹配类型
|
long |
maxDepth()
获取最大的请求深度
|
CrawlerBuilder |
maxDepth(long maxDepth)
设置最大的请求深度
|
int |
maxRedirects()
获取要遵循的最大重定向数
|
CrawlerBuilder |
maxRedirects(int maxRedirects)
设置要遵循的最大重定向数
|
boolean |
normalizeUri()
确定客户端是否应规范请求中的URI
|
CrawlerBuilder |
normalizeUri(boolean normalizeUri)
设置客户端是否应规范请求中的URI
|
PageRule |
pageRule()
获取内容匹配规则
|
CrawlerBuilder |
pageRule(PageRule pageRule)
设置内容匹配规则
|
boolean |
redirectsEnabled()
获取是否应自动处理重定向
|
CrawlerBuilder |
redirectsEnabled(boolean redirectsEnabled)
设置是否应自动处理重定向
|
String |
referrer()
获取请求来源页
此值为空时表示由内核智能处理 |
CrawlerBuilder |
referrer(String referrer)
设置请求来源页
|
boolean |
relativeRedirectsAllowed()
获取确定是否应拒绝相对重定向
|
CrawlerBuilder |
relativeRedirectsAllowed(boolean relativeRedirectsAllowed)
设置确定是否应拒绝相对重定向
|
int |
retryCount()
获取请求失败时的重试次数
|
CrawlerBuilder |
retryCount(int retryCount)
设置请求失败时的重试次数
|
CrawlerBuilder |
setExtractRules(List<ExtractRule> list)
设置 内容提取规则
会清空原始的内容提取规则 |
CrawlerBuilder |
setExtractRules(String key,
List<ExtractFieldRule> list)
根据内容提取规则的编码设置该内容提取规则的提取规则
|
CrawlerBuilder |
setHeaders(List<HeaderRule> list)
清空原始值后再设置请求头参数
|
CrawlerBuilder |
setLinkRules(Set<MatcherRule> linkRules)
清空原始链接提取规则后设置链接提取规则
|
SiteRule |
site()
获取站点配置规则数据
|
CrawlerBuilder |
site(SiteRule site)
设置站点配置规则数据
|
String |
startUrl()
获取起始链接地址
多个起始链接之间用半角逗号隔开 |
CrawlerBuilder |
startUrl(String startUrl)
设置 起始链接地址
多个起始链接之间用半角逗号隔开 |
int |
threadNum()
风铃虫解析时线程数
默认线程数为1 |
CrawlerBuilder |
threadNum(int threadNum)
设置 风铃虫解析时线程数 默认线程数为1
|
String |
userAgent()
获取浏览器标识 ,此值为空时表示每次请求都会随机从内置浏览器标识中选择一个
|
CrawlerBuilder |
userAgent(String userAgent)
设置浏览器标识
|
long |
waitTime()
获取超时等待时间,单位为毫秒,默认为300000毫秒(300秒),连续间隔多长时间后没有新的请求任务表明此任务已经结束
默认为300000毫秒(300秒) |
CrawlerBuilder |
waitTime(long waitTimeInSeconds)
设置超时等待时间,单位为毫秒,默认为300000毫秒(300秒),连续间隔多长时间后没有新的请求任务表明此任务已经结束
默认为300000毫秒(300秒) |
public static CrawlerBuilder create()
public static CrawlerBuilder create(CrawlerRule crawlerRule)
crawlerRule
- 风铃虫规则public long interval()
public CrawlerBuilder interval(long intervalInSeconds)
intervalInSeconds
- 每次请求的间隔时间,单位为毫秒,必须不小于0public long waitTime()
public CrawlerBuilder waitTime(long waitTimeInSeconds)
waitTimeInSeconds
- 超时等待时间,单位为毫秒,必须大于0public int threadNum()
public CrawlerBuilder threadNum(int threadNum)
threadNum
- 风铃虫解析时线程数,必须大于0public SiteRule site()
public CrawlerBuilder site(SiteRule site)
site
- 站点配置规则数据public String userAgent()
public CrawlerBuilder userAgent(String userAgent)
userAgent
- 浏览器标识,此值为空时表示每次请求都会随机从内置浏览器标识中选择一个public String referrer()
public CrawlerBuilder referrer(String referrer)
referrer
- 请求来源页,此值为空时表示由内核智能处理public String cookieValue()
public CrawlerBuilder cookieValue(String cookieValue)
cookieValue
- 请求时携带cookie信息,此值为空时表示由内核智能处理public String cacheControl()
public CrawlerBuilder cacheControl(String cacheControl)
cacheControl
- 网页缓存策略,默认为 max-age=0public List<HeaderRule> headers()
public CrawlerBuilder addHeader(HeaderRule headerRule)
headerRule
- 请求头参数public CrawlerBuilder addHeaders(List<HeaderRule> list)
list
- 请求头参数public CrawlerBuilder setHeaders(List<HeaderRule> list)
list
- 请求头参数public String failureMark()
public CrawlerBuilder failureMark(String failureMark)
failureMark
- 失败标志,此值为空时表示不开启此功能public int interceptCount()
public CrawlerBuilder interceptCount(int interceptCount)
interceptCount
- 拦截次数阀域值,此值小于1时表示不开启此功能public int retryCount()
public CrawlerBuilder retryCount(int retryCount)
retryCount
- 请求失败时的重试次数,连续多次在下载内容中获取到失败标识时的重试此次,默认为5public long maxDepth()
public CrawlerBuilder maxDepth(long maxDepth)
maxDepth
- 最大的请求深度,此值为0或负数时表示不进行深度限制public int connectTimeout()
public CrawlerBuilder connectTimeout(int connectTimeout)
connectTimeout
- 确定连接建立之前的超时时间(以毫秒为单位),非正数时表示不开启此功能public boolean redirectsEnabled()
public CrawlerBuilder redirectsEnabled(boolean redirectsEnabled)
redirectsEnabled
- 是否应自动处理重定向,默认为truepublic String cookieSpec()
public CrawlerBuilder cookieSpec(String cookieSpec)
cookieSpec
- 确定用于HTTP状态管理的cookie规范的名称public boolean relativeRedirectsAllowed()
public CrawlerBuilder relativeRedirectsAllowed(boolean relativeRedirectsAllowed)
relativeRedirectsAllowed
- 确定是否应拒绝相对重定向public boolean circularRedirectsAllowed()
public CrawlerBuilder circularRedirectsAllowed(boolean circularRedirectsAllowed)
circularRedirectsAllowed
- 是否应允许循环重定向public boolean normalizeUri()
public CrawlerBuilder normalizeUri(boolean normalizeUri)
normalizeUri
- 客户端是否应规范请求中的URIpublic int maxRedirects()
public CrawlerBuilder maxRedirects(int maxRedirects)
maxRedirects
- 要遵循的最大重定向数public boolean contentCompressionEnabled()
public CrawlerBuilder contentCompressionEnabled(boolean contentCompressionEnabled)
contentCompressionEnabled
- 是否请求目标服务器压缩内容public LinkRule link()
public CrawlerBuilder link(LinkRule link)
link
- 链接解析规则public Set<MatcherRule> linkRules()
public CrawlerBuilder setLinkRules(Set<MatcherRule> linkRules)
linkRules
- 链接提取规则public CrawlerBuilder addLinkRules(Set<MatcherRule> linkRules)
linkRules
- 链接提取规则public CrawlerBuilder addLinkRule(MatcherRule linkRule)
linkRule
- 链接提取规则public String startUrl()
public CrawlerBuilder startUrl(String startUrl)
startUrl
- 起始链接地址public ContentRule content()
public CrawlerBuilder content(ContentRule content)
content
- 内容解析规则public PageRule pageRule()
public CrawlerBuilder pageRule(PageRule pageRule)
pageRule
- 内容匹配规则public MatcherRule contentPageRule()
public CrawlerBuilder contentPageRule(MatcherRule contentPageRule)
contentPageRules
- 内容页地址规则 ,多个规则之间用半角逗号隔开public Type matcherType()
public CrawlerBuilder matcherType(Type matcherType)
matcherType
- public String matcherPattern()
public CrawlerBuilder matcherPattern(String matcherPattern)
matcherPattern
- 内容匹配参数public String matcherTarget()
public CrawlerBuilder matcherTarget(String matcherTarget)
matcherTarget
- 期待匹配值public Boolean matcherMode()
public CrawlerBuilder matcherMode(Boolean matcherMode)
matcherMode
- true表示必须包含期待匹配参数,false标识不能包含期待匹配参数public Boolean matcherCaseSensitive()
public CrawlerBuilder matcherCaseSensitive(Boolean matcherCaseSensitive)
matcherCaseSensitive
- 是否大小写敏感,true表示敏感public Boolean matcherFuzzy()
public CrawlerBuilder matcherFuzzy(Boolean matcherFuzzy)
matcherFuzzy
- true表示为模糊匹配public List<ExtractRule> extractRules()
public CrawlerBuilder addExtractRules(List<ExtractRule> list)
list
- 内容提取规则public CrawlerBuilder setExtractRules(List<ExtractRule> list)
list
- 内容提取规则public ExtractRule extractRule(String key)
key
- 内容提取规则的编码获取public CrawlerBuilder addExtractRule(ExtractRule extractRule)
extractRule
- 内容提取规则public List<ExtractFieldRule> fieldExtractRule(String key)
key
- 内容提取规则的编码public CrawlerBuilder addFieldExtractRules(String key, List<ExtractFieldRule> list)
key
- 内容提取规则的编码list
- 该内容提取规则的提取规则public CrawlerBuilder addExtractRule(String key, ExtractFieldRule fieldExtractRule)
key
- 内容提取规则的编码fieldExtractRule
- 该内容提取规则的提取规则public CrawlerBuilder setExtractRules(String key, List<ExtractFieldRule> list)
key
- 内容提取规则的编码list
- 该内容提取规则的提取规则public CrawlerRule build()
public Crawler creatCrawler()
Copyright © 2020 Pivotal Software, Inc.. All rights reserved.