diff --git a/webmagic-extension/src/main/java/us/codecraft/webmagic/model/PageModelExtractor.java b/webmagic-extension/src/main/java/us/codecraft/webmagic/model/PageModelExtractor.java index 8fb0c1ae..1e25a46c 100644 --- a/webmagic-extension/src/main/java/us/codecraft/webmagic/model/PageModelExtractor.java +++ b/webmagic-extension/src/main/java/us/codecraft/webmagic/model/PageModelExtractor.java @@ -19,6 +19,8 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import static us.codecraft.webmagic.model.annotation.ExtractBy.Source.RawText; + /** * The main internal logic of page model extractor. * @@ -125,9 +127,12 @@ class PageModelExtractor { ExtractBy extractBy = field.getAnnotation(ExtractBy.class); if (extractBy != null) { Selector selector = ExtractorUtils.getSelector(extractBy); - + ExtractBy.Source source0 = extractBy.source(); + if (extractBy.type()== ExtractBy.Type.JsonPath){ + source0 = RawText; + } FieldExtractor.Source source = null; - switch (extractBy.source()){ + switch (source0){ case RawText: source = FieldExtractor.Source.RawText; break; diff --git a/webmagic-extension/src/test/java/us/codecraft/webmagic/model/PageModelExtractorTest.java b/webmagic-extension/src/test/java/us/codecraft/webmagic/model/PageModelExtractorTest.java index 192856f7..f212628b 100644 --- a/webmagic-extension/src/test/java/us/codecraft/webmagic/model/PageModelExtractorTest.java +++ b/webmagic-extension/src/test/java/us/codecraft/webmagic/model/PageModelExtractorTest.java @@ -77,7 +77,7 @@ public class PageModelExtractorTest { public static class ModelJsonStr { - @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.name",source = ExtractBy.Source.RawText) + @ExtractBy(type = ExtractBy.Type.JsonPath, value = "$.name") private String name; }