fix a null domain error

pull/17/head
yihua.huang 12 years ago
parent f413450403
commit 5c96407a3d

@ -1,5 +1,7 @@
package us.codecraft.webmagic;
import us.codecraft.webmagic.utils.UrlUtils;
import java.util.*;
/**
@ -90,6 +92,11 @@ public class Site {
* @return domain
*/
public String getDomain() {
if (domain == null) {
if (startUrls.size() > 0) {
domain = UrlUtils.getDomain(startUrls.get(0));
}
}
return domain;
}
@ -150,6 +157,7 @@ public class Site {
/**
*
*
* @return
*/
public List<String> getStartUrls() {
@ -158,6 +166,7 @@ public class Site {
/**
*
*
* @param startUrl
* @return this
*/
@ -179,6 +188,7 @@ public class Site {
/**
*
*
* @return
*/
public int getSleepTime() {
@ -187,6 +197,7 @@ public class Site {
/**
* 0
*
* @return
*/
public int getRetryTimes() {
@ -195,6 +206,7 @@ public class Site {
/**
* 0
*
* @return this
*/
public Site setRetryTimes(int retryTimes) {
@ -219,7 +231,7 @@ public class Site {
return true;
}
public Task toTask(){
public Task toTask() {
return new Task() {
@Override
public String getUUID() {

@ -4,6 +4,8 @@ import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.model.ExtractBy;
import us.codecraft.webmagic.model.OOSpider;
import us.codecraft.webmagic.model.TargetUrl;
import us.codecraft.webmagic.pipeline.ConsolePipeline;
import us.codecraft.webmagic.pipeline.JsonFilePipeline;
/**
* @author code4crafter@gmail.com <br>
@ -28,7 +30,7 @@ public class OschinaBlog implements Blog{
}
public static void main(String[] args) {
OOSpider.create(Site.me().addStartUrl("http://my.oschina.net/flashsword/blog"), OschinaBlog.class).run();
OOSpider.create(Site.me().addStartUrl("http://my.oschina.net/flashsword/blog"), OschinaBlog.class).pipeline(new ConsolePipeline()).pipeline(new JsonFilePipeline()).run();
}
public String getTitle() {

Loading…
Cancel
Save