add some samples
parent
7a4dbb1f15
commit
7ee567b804
|
@ -0,0 +1,13 @@
|
||||||
|
package us.codecraft.webmagic.annotation.samples;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yihua.huang@dianping.com <br>
|
||||||
|
* @date: 13-8-2 <br>
|
||||||
|
* Time: 上午8:10 <br>
|
||||||
|
*/
|
||||||
|
public interface Blog {
|
||||||
|
|
||||||
|
public String getTitle();
|
||||||
|
|
||||||
|
public String getContent();
|
||||||
|
}
|
|
@ -11,7 +11,7 @@ import us.codecraft.webmagic.annotation.TargetUrl;
|
||||||
* Time: 上午7:52 <br>
|
* Time: 上午7:52 <br>
|
||||||
*/
|
*/
|
||||||
@TargetUrl("http://dengminhui.iteye.com/blog/*")
|
@TargetUrl("http://dengminhui.iteye.com/blog/*")
|
||||||
public class IteyeBlog {
|
public class IteyeBlog implements Blog{
|
||||||
|
|
||||||
@ExtractBy("//title")
|
@ExtractBy("//title")
|
||||||
private String title;
|
private String title;
|
||||||
|
@ -31,4 +31,11 @@ public class IteyeBlog {
|
||||||
Spider.create(Site.me().addStartUrl("http://dengminhui.iteye.com/blog"),IteyeBlog.class).run();
|
Spider.create(Site.me().addStartUrl("http://dengminhui.iteye.com/blog"),IteyeBlog.class).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
package us.codecraft.webmagic.annotation.samples;
|
||||||
|
|
||||||
|
import us.codecraft.webmagic.Site;
|
||||||
|
import us.codecraft.webmagic.Spider;
|
||||||
|
import us.codecraft.webmagic.annotation.ExtractBy;
|
||||||
|
import us.codecraft.webmagic.annotation.TargetUrl;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author yihua.huang@dianping.com <br>
|
||||||
|
* @date: 13-8-2 <br>
|
||||||
|
* Time: 上午7:52 <br>
|
||||||
|
*/
|
||||||
|
@TargetUrl("http://my.oschina.net/flashsword/blog/\\d+")
|
||||||
|
public class OschinaBlog implements Blog{
|
||||||
|
|
||||||
|
@ExtractBy("//title")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
@ExtractBy(value = "div.BlogContent",type = ExtractBy.Type.Css)
|
||||||
|
private String content;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "OschinaBlog{" +
|
||||||
|
"title='" + title + '\'' +
|
||||||
|
", content='" + content + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Spider.create(Site.me().addStartUrl("http://my.oschina.net/flashsword/blog"),OschinaBlog.class).run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getContent() {
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue