Bot releases are hidden (Show)
SeimiDownloader
方便更灵活的定制自己的数据获取需求public class MyCoustomDownloader implements SeimiDownloader {
@Override
public Response process(Request request) throws Exception {
Response seimiResponse = new Response();
seimiResponse.setSeimiHttpType(SeimiHttpType.OK_HTTP3);
seimiResponse.setRealUrl(request.getUrl());
seimiResponse.setUrl(request.getUrl());
seimiResponse.setRequest(request);
seimiResponse.setMeta(request.getMeta());
seimiResponse.setBodyType(BodyType.TEXT);
String content = webGetDo(request);
seimiResponse.setContent(content);
return seimiResponse;
}
@Override
public Response metaRefresh(String s) throws Exception {
//看自己情况,可以不实现不处理
return null;
}
@Override
public int statusCode() {
return 200;
}
@Override
public void addCookies(String s, List<SeimiCookie> list) {
//to do
}
}
其中 webGetDo()
是自定义逻辑,这里没有列出来,仅作示意,你可以随意实现你想实现的逻辑。
Request next = Request.build(url, MyCrawler::parseDetail);
next.setDownloader(MyCoustomDownloader.class);
push(next);
-Dseimi.crawler.thread-num=xx
自定义每个Crawler
的工作线程数,最小值为1Published by zhegexiaohuozi over 1 year ago
JsoupXpath
最新版本 https://github.com/zhegexiaohuozi/JsoupXpath/releases/tag/v2.5.2
完美支持SpringBoot,可以尽情的集成SpringBoot现有生态,demo参考
回调函数支持方法引用,设置起来更自然
push(Request.build(s.toString(),Basic::getTitle));
SeimiConfig
进行配置,包括 Redis集群信息,SeimiAgent信息等,SpringBoot模式则通过SpringBoot标准模式配置常规模式:
SeimiConfig config = new SeimiConfig();
config.setSeimiAgentHost("127.0.0.1");
//config.redisSingleServer().setAddress("redis://127.0.0.1:6379");
Seimi s = new Seimi(config);
s.goRun("basic");
SpringBoot模式,在application.properties中配置
seimi.crawler.enabled=true
# 指定要发起start请求的crawler的name
seimi.crawler.names=basic,test
seimi.crawler.seimi-agent-host=xx
seimi.crawler.seimi-agent-port=xx
#开启分布式队列
seimi.crawler.enable-redisson-queue=true
#自定义bloomFilter预期插入次数,不设置用默认值 ()
#seimi.crawler.bloom-filter-expected-insertions=
#自定义bloomFilter预期的错误率,0.001为1000个允许有一个判断错误的。不设置用默认值(0.001)
#seimi.crawler.bloom-filter-false-probability=
分布式队列改用Redisson实现,底层依旧为redis,去重引入BloomFilter以提高空间利用率,一个线上的BloomFilter调参模拟器地址
JDK要求 1.8+
JsoupXpath同步升级至基于Antlr4重构的2.0版本,带来更为强大的Xpath语法支持
Request
对象中,通过header
(map)来自定义本次请求的header,以及支持通过seimiCookies
来自定义cookies,自定义cookies会直接进入cookiesStore,对同域下第二次请求依然有效cn.wanghaomiao.seimi.boot.Run
支持CommandLineParser
,可以使用 -c
和-p
来传参,其中-c
用来指定crawlernames,多个用','分隔,-p
指定一个端口,可以选择性的启动一个内嵌的http服务,并开启使用内嵌http接口maven-seimicrawler-plugin
打包插件升级为1.3.0,完善Linux下的脚本,并增加启动配置文件,可以到maven-seimicrawler-plugin主页详细查看
OkhttpDownloader
支持处理contentType
头中没有指定编码的中文页面@Crawler
注解中的httpTimeOut
属性自定义http请求的超时时间,默认15000ms
附件中的demo通过maven-seimicrawler-plugin打包生成。如果不熟悉maven可以直接使用里面的lib目录设置依赖,同时也可以直接运行示例查看效果。运行方法可以阅读maven-seimicrawler-plugin进行了解。
Published by zhegexiaohuozi over 8 years ago
okhttp3
实现,且支持通过@Crawler
注解中的httpType
自由切换为apache httpclientv0.3.1
这一版是SeimiCrawler比较重大的一次更新,伴之而来的亦是更强悍的抓取体验。