在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:CasperMagic开源软件地址:https://gitee.com/buaalining/CasperMagic开源软件介绍:#CasperMagic CasperMagic是基于PlantomJS&CasperJS和WebMagic的一个整合。CasperJS可以很方便对动态网页进行测试,但Javascript不太容易执行数据持久化和数据分析,而一般的爬虫很难抓取动态网页的内容或对页面进行操作并爬取。CasperMagic是基于WebMagic对CasperJS的封装。 ##工作模式 和CasperJS的工作模式类似,CasperMagic同样采用分步的方式。当需要对页面进行操作时,基于一个tag的操作作为一个Action,多个Action形成一个ActionChain,按照ActionChain的顺序依次执行Action的操作,最后得到操作后的页面,使用WebMagic中抽取数据。 CasperMagic的执行环境需要安装PlantomJS和CasperJS,并将路径配置到CasperMagic。CasperMagic根据ActionChain生成相应的js脚本,然后执行脚本得到网页数据。 ActionChain的配置相当简单 ActionChain chain=new ActionChain(); ActionNode node=new ActionNode(); node.setNodetype(ActionNodeType.Click).setEventElement("div.article-content p a"); chain=ActionFactory.CreateActionChain(node).ChainEnd("click.js"); Spider.create(this).startUrls(url).setDownloader(new JsDownload(env,chain).setEnableclick(true)).run(); JsDownload是CasperMagic实现的获取动态网页的下载器。 |
请发表评论