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