package com.wilian.astro.webmagic.follifollie;
import com.wilian.astro.webmagic.vo.WatchVO;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;
/**
*
* @ClassName: OfficialWebsitePageProcessor
* @Description: 官网数据
* @author PENGDI052
* @date 2018年4月16日
*
*/
public class OfficialWebsitePageProcessor implements PageProcessor {
// 官网手表入口页面&分页
// http://www.follifollie.com.cn/ch-ch/online-shop/watches/all#pg=1
// 产品详情页面
// http://www.follifollie.com.cn/ch-ch/online-shop/watches/jewelled/wf9a019bsw_xx-carousel-%E7%B3%BB%E5%88%97%E6%89%8B%E8%A1%A8
private static final String DETAIL_URL = "http://www.follifollie.com.cn/ch-ch/online-shop/watches/[a-zA-z]+/[\\w]+";
private static final String LIST_URL = "http://www.follifollie.com.cn/ch-ch/online-shop/watches/all#pg=[0-9]+";
private Site site = Site.me().setRetryTimes(3).setSleepTime(1000);
public void process(Page page) {
System.out.println("11");
if (page.getUrl().regex(LIST_URL).match()) {
page.addTargetRequests(page.getHtml().links().regex(DETAIL_URL).all());
}
else{
WatchVO watch = new WatchVO();
watch.setSource("官网");
watch.setUrl(page.getUrl().get());
watch.setBrand("Folli Follie");
watch.setSeries(page.getHtml().xpath("/html/body/div[1]/section[1]/div/div/div[3]/div/div/div[1]/div[2]/div/h1/text()").get());
System.out.println(watch.toString());
}
}
public Site getSite() {
return site;
}
public static void main(String[] args) {
Spider.create(new OfficialWebsitePageProcessor())
.addUrl(new String[]{"http://www.follifollie.com.cn/ch-ch/online-shop/watches/all#pg=1"})
.thread(5)
.run();
}
}
log4j.properties
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.Threshold=INFO
log4j.appender.stdout.ImmediateFlush=true
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %X{RequestId} - %m%n
log4j.appender.mongodb=org.apache.log4j.ConsoleAppender
log4j.appender.mongodb.Target=System.out
log4j.appender.mongodb.Threshold=DEBUG
log4j.appender.mongodb.ImmediateFlush=true
log4j.appender.mongodb.layout=org.apache.log4j.PatternLayout
log4j.appender.mongodb.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss,SSS} %5p %X{RequestId} - %m%n
package com.wilian.astro.webmagic.vo;
import java.util.Date;
public class WatchVO {
private String brand; // 品牌
private String imgUrl; // 图片
private String salePrice ;//当前售价
private String discount; //折扣
private String price ; //挂牌价格
private String model; //型号,品牌下的具体型号
private String style ; //类型,石英,陶瓷,机械
private String series ;// 系列
private String source; //数据来源
private String url ; //来源网址
private String stock; //库存
private Date createDate;//创建时间
private Date updateDate; //更新时间
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getImgUrl() {
return imgUrl;
}
public void setImgUrl(String imgUrl) {
this.imgUrl = imgUrl;
}
public String getSalePrice() {
return salePrice;
}
public void setSalePrice(String salePrice) {
this.salePrice = salePrice;
}
public String getDiscount() {
return discount;
}
public void setDiscount(String discount) {
this.discount = discount;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public String getStyle() {
return style;
}
public void setStyle(String style) {
this.style = style;
}
public String getSource() {
return source;
}
public void setSource(String source) {
this.source = source;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getStock() {
return stock;
}
public void setStock(String stock) {
this.stock = stock;
}
public Date getCreateDate() {
return createDate;
}
public void setCreateDate(Date createDate) {
this.createDate = createDate;
}
public Date getUpdateDate() {
return updateDate;
}
public void setUpdateDate(Date updateDate) {
this.updateDate = updateDate;
}
public String getModel() {
return model;
}
public void setModel(String model) {
this.model = model;
}
public String getSeries() {
return series;
}
public void setSeries(String series) {
this.series = series;
}
public String toString() {
return "WatchVO [brand=" + brand + ", imgUrl=" + imgUrl
+ ", salePrice=" + salePrice + ", discount=" + discount
+ ", price=" + price + ", model=" + model + ", style=" + style
+ ", series=" + series + ", source=" + source + ", url=" + url
+ ", stock=" + stock + ", createDate=" + createDate
+ ", updateDate=" + updateDate + "]";
}
}
相关推荐
webmagic爬虫项目 代码案例基于maven项目构建 。使用说明:SpiderOschinaServiceImpl 的main方法
本项目是基于Java的WebMagic爬虫框架设计源码,包含291个文件,其中主要包含233个java源代码文件,18个xml配置文件等。系统采用了Java、HTML、JavaScript、Ruby、Python、Shell和Kotlin技术,实现了WebMagic爬虫框架...
最新Java WebMagic爬虫教程(包括:HttClient/Jsoup的使用教程)、爬虫案例项目
webMagic爬虫抓取某个博客全部文章名称,简单列子,可以做参考
基于webmagic爬虫表情包案例.zip
反爬虫应对: 由于爬虫的存在,一些网站采取了反爬虫措施,如验证码、IP封锁等。爬虫工程师需要设计相应的策略来应对这些挑战。 爬虫在各个领域都有广泛的应用,包括搜索引擎索引、数据挖掘、价格监测、新闻聚合等...
本测试Demo共包含两个网站,涉及到三个数据页面的操作,三个Controller层由浅及深,可以更快入手,数据才存储数据库的时候,做了重复性的判断,避免重复添加。
简单的通过webMagic技术来进行数据的爬取,通过服务端请求数据,后台进行爬取别的网站上数据返回并显示
该程序能够通过爬虫工具自动下载国家统计中心的行政区划代码到指定的数据库中的表中。将工程导入eclipse中,运行GithubRepoPageProcessor类的main方法即可,需要对数据库进行配置,以及建相应表建表语句在database...
爬虫-webmagic学习总结文档,主要介绍本人学习爬虫的小总结
闲来无事最近写了一个全新的爬虫框架WebMagic整合springboot的爬虫程序,不清楚WebMagic的童鞋可以先查看官网了解什么是Webmagic,顺便说说用springboot时遇到的一些坑
WebMagic是一个简单灵活的Java爬虫框架。基于WebMagic,你可以快速开发出一个高效、易维护的爬虫。 特性: 简单的API,可快速上手 模块化的结构,可轻松扩展(使用者请遵守当地法律)
maven搭建,可以直接运行SpiderOschinaServiceImpl类里的main方法
z2py 最爱片源网源代码(基于Webmagic爬虫实现) 演示地址:http:
主要介绍了使用webmagic实现爬虫程序示例,需要的朋友可以参考下
基于WebMagic爬虫框架的全部依赖jar包,下载即用,如何使用可以查看我的博客有详细的讲解基于WebMagic爬虫框架的爬虫开发。
WebMagic抓取CSDN博客通过JDBC保存到数据库中去
webmagic爬虫修复HTTPS下无法抓取只支持TLSv1.2的站点的bug后重新打包的jar,用这个替换原jar,在爬取HTTPS站点后就不会报错了。