#45 Remove multi in ExtractBy
parent
aaa53f58c7
commit
486d9d276f
|
@ -23,14 +23,18 @@ public class AppStore {
|
||||||
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..userRatingCount")
|
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..userRatingCount")
|
||||||
private int userRatingCount;
|
private int userRatingCount;
|
||||||
|
|
||||||
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..screenshotUrls",multi = true)
|
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..screenshotUrls")
|
||||||
private List<String> screenshotUrls;
|
private List<String> screenshotUrls;
|
||||||
|
|
||||||
|
@ExtractBy(type = ExtractBy.Type.JsonPath, value = "$..supportedDevices")
|
||||||
|
private List<String> supportedDevices;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
AppStore appStore = OOSpider.create(Site.me(), AppStore.class).<AppStore>get("http://itunes.apple.com/lookup?id=653350791&country=cn&entity=software");
|
AppStore appStore = OOSpider.create(Site.me(), AppStore.class).<AppStore>get("http://itunes.apple.com/lookup?id=653350791&country=cn&entity=software");
|
||||||
System.out.println(appStore.trackName);
|
System.out.println(appStore.trackName);
|
||||||
System.out.println(appStore.description);
|
System.out.println(appStore.description);
|
||||||
System.out.println(appStore.userRatingCount);
|
System.out.println(appStore.userRatingCount);
|
||||||
System.out.println(appStore.screenshotUrls);
|
System.out.println(appStore.screenshotUrls);
|
||||||
|
System.out.println(appStore.supportedDevices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,9 @@ class PageModelExtractor {
|
||||||
if (regexPattern.trim().equals("")) {
|
if (regexPattern.trim().equals("")) {
|
||||||
regexPattern = ".*";
|
regexPattern = ".*";
|
||||||
}
|
}
|
||||||
fieldExtractor = new FieldExtractor(field, new RegexSelector(regexPattern), FieldExtractor.Source.Url, extractByUrl.notNull(), extractByUrl.multi());
|
fieldExtractor = new FieldExtractor(field,
|
||||||
|
new RegexSelector(regexPattern), FieldExtractor.Source.Url, extractByUrl.notNull(),
|
||||||
|
extractByUrl.multi() || List.class.isAssignableFrom(field.getType()));
|
||||||
Method setterMethod = getSetterMethod(clazz, field);
|
Method setterMethod = getSetterMethod(clazz, field);
|
||||||
if (setterMethod != null) {
|
if (setterMethod != null) {
|
||||||
fieldExtractor.setSetterMethod(setterMethod);
|
fieldExtractor.setSetterMethod(setterMethod);
|
||||||
|
@ -157,7 +159,7 @@ class PageModelExtractor {
|
||||||
selector = new AndSelector(ExtractorUtils.getSelectors(extractBies));
|
selector = new AndSelector(ExtractorUtils.getSelectors(extractBies));
|
||||||
}
|
}
|
||||||
fieldExtractor = new FieldExtractor(field, selector, comboExtract.source() == ComboExtract.Source.RawHtml ? FieldExtractor.Source.RawHtml : FieldExtractor.Source.Html,
|
fieldExtractor = new FieldExtractor(field, selector, comboExtract.source() == ComboExtract.Source.RawHtml ? FieldExtractor.Source.RawHtml : FieldExtractor.Source.Html,
|
||||||
comboExtract.notNull(), comboExtract.multi());
|
comboExtract.notNull(), comboExtract.multi() || List.class.isAssignableFrom(field.getType()));
|
||||||
Method setterMethod = getSetterMethod(clazz, field);
|
Method setterMethod = getSetterMethod(clazz, field);
|
||||||
if (setterMethod != null) {
|
if (setterMethod != null) {
|
||||||
fieldExtractor.setSetterMethod(setterMethod);
|
fieldExtractor.setSetterMethod(setterMethod);
|
||||||
|
@ -172,7 +174,7 @@ class PageModelExtractor {
|
||||||
if (extractBy != null) {
|
if (extractBy != null) {
|
||||||
Selector selector = ExtractorUtils.getSelector(extractBy);
|
Selector selector = ExtractorUtils.getSelector(extractBy);
|
||||||
fieldExtractor = new FieldExtractor(field, selector, extractBy.source() == ExtractBy.Source.RawHtml ? FieldExtractor.Source.RawHtml : FieldExtractor.Source.Html,
|
fieldExtractor = new FieldExtractor(field, selector, extractBy.source() == ExtractBy.Source.RawHtml ? FieldExtractor.Source.RawHtml : FieldExtractor.Source.Html,
|
||||||
extractBy.notNull(), extractBy.multi());
|
extractBy.notNull(), extractBy.multi() || List.class.isAssignableFrom(field.getType()));
|
||||||
Method setterMethod = getSetterMethod(clazz, field);
|
Method setterMethod = getSetterMethod(clazz, field);
|
||||||
if (setterMethod != null) {
|
if (setterMethod != null) {
|
||||||
fieldExtractor.setSetterMethod(setterMethod);
|
fieldExtractor.setSetterMethod(setterMethod);
|
||||||
|
@ -359,7 +361,7 @@ class PageModelExtractor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setField(Object o, FieldExtractor fieldExtractor, Object value) throws IllegalAccessException, InvocationTargetException {
|
private void setField(Object o, FieldExtractor fieldExtractor, Object value) throws IllegalAccessException, InvocationTargetException {
|
||||||
if (value==null){
|
if (value == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (fieldExtractor.getSetterMethod() != null) {
|
if (fieldExtractor.getSetterMethod() != null) {
|
||||||
|
|
|
@ -75,6 +75,8 @@ public @interface ComboExtract {
|
||||||
* Define whether the extractor return more than one result.
|
* Define whether the extractor return more than one result.
|
||||||
* When set to 'true', the extractor return a list of string (so you should define the field as List). <br>
|
* When set to 'true', the extractor return a list of string (so you should define the field as List). <br>
|
||||||
*
|
*
|
||||||
|
* Deprecated since 0.4.2. This option is determined automatically by the class of field.
|
||||||
|
* @deprecated since 0.4.2
|
||||||
* @return whether the extractor return more than one result
|
* @return whether the extractor return more than one result
|
||||||
*/
|
*/
|
||||||
boolean multi() default false;
|
boolean multi() default false;
|
||||||
|
|
|
@ -67,6 +67,8 @@ public @interface ExtractBy {
|
||||||
* Define whether the extractor return more than one result.
|
* Define whether the extractor return more than one result.
|
||||||
* When set to 'true', the extractor return a list of string (so you should define the field as List). <br>
|
* When set to 'true', the extractor return a list of string (so you should define the field as List). <br>
|
||||||
*
|
*
|
||||||
|
* Deprecated since 0.4.2. This option is determined automatically by the class of field.
|
||||||
|
* @deprecated since 0.4.2
|
||||||
* @return whether the extractor return more than one result
|
* @return whether the extractor return more than one result
|
||||||
*/
|
*/
|
||||||
boolean multi() default false;
|
boolean multi() default false;
|
||||||
|
|
|
@ -33,6 +33,8 @@ public @interface ExtractByUrl {
|
||||||
* Define whether the extractor return more than one result.
|
* Define whether the extractor return more than one result.
|
||||||
* When set to 'true', the extractor return a list of string (so you should define the field as List). <br>
|
* When set to 'true', the extractor return a list of string (so you should define the field as List). <br>
|
||||||
*
|
*
|
||||||
|
* Deprecated since 0.4.2. This option is determined automatically by the class of field.
|
||||||
|
* @deprecated since 0.4.2
|
||||||
* @return whether the extractor return more than one result
|
* @return whether the extractor return more than one result
|
||||||
*/
|
*/
|
||||||
boolean multi() default false;
|
boolean multi() default false;
|
||||||
|
|
Loading…
Reference in New Issue