add failfast
parent
7ee567b804
commit
516ff3310d
|
@ -13,6 +13,8 @@ import java.lang.annotation.Target;
|
|||
@Target({ElementType.FIELD})
|
||||
public @interface ExtractBy {
|
||||
|
||||
|
||||
//TODO: add list support
|
||||
String value();
|
||||
|
||||
public enum Type {XPath, Regex, Css};
|
||||
|
|
|
@ -42,6 +42,9 @@ class PageModelExtractor {
|
|||
fieldExtractors = new ArrayList<FieldExtractor>();
|
||||
for (Field field : clazz.getDeclaredFields()) {
|
||||
field.setAccessible(true);
|
||||
if (!field.getType().isAssignableFrom(String.class)){
|
||||
throw new IllegalStateException("Field "+field.getName()+" must be string");
|
||||
}
|
||||
ExtractBy extractBy = field.getAnnotation(ExtractBy.class);
|
||||
if (extractBy != null) {
|
||||
String value = extractBy.value();
|
||||
|
|
|
@ -14,7 +14,7 @@ import us.codecraft.webmagic.annotation.TargetUrl;
|
|||
public class IteyeBlog implements Blog{
|
||||
|
||||
@ExtractBy("//title")
|
||||
private String title;
|
||||
private int title;
|
||||
|
||||
@ExtractBy(value = "div#blog_content",type = ExtractBy.Type.Css)
|
||||
private String content;
|
||||
|
@ -32,7 +32,7 @@ public class IteyeBlog implements Blog{
|
|||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
|
|
Loading…
Reference in New Issue