webmagic
webmagic copied to clipboard
很慢,5秒的耗时怎么避免?
MyProcessor tool = new MyProcessor(); Spider.create(tool).addUrl("http://10.27.129.105:8000/").addPipeline(collectorPipeline) .run(); System.out.println("Run takes1: "+new Date());
在MyProcessor的方法process(Page page)最后打印系统时间:System.out.println("Run takes11: "+new Date());
运行结果: Run takes11: Tue Jul 10 18:52:48 CST 2018 Run takes1: Tue Jul 10 18:52:53 CST 2018
请问这5秒的耗时怎么避免?完全是webmagic的耗时
run()方法会连接到网络并且爬取数据,5秒耗时已经把爬取过程包含进去了,主要的耗时应该在网络IO部分。
爬虫默认有个5秒睡眠时间,可以调成0