|
|
|
@ -3,6 +3,7 @@ package us.codecraft.webmagic.selector;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import us.codecraft.xsoup.XTokenQueue;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -52,6 +53,20 @@ public class Json extends PlainText {
|
|
|
|
|
@Override
|
|
|
|
|
public Selectable jsonPath(String jsonPath) {
|
|
|
|
|
JsonPathSelector jsonPathSelector = new JsonPathSelector(jsonPath);
|
|
|
|
|
return selectList(jsonPathSelector,getSourceTexts());
|
|
|
|
|
List<String> results = new ArrayList<String>();
|
|
|
|
|
for (String string : getSourceTexts()) {
|
|
|
|
|
List<String> result = jsonPathSelector.selectList(string);
|
|
|
|
|
results.addAll(result);
|
|
|
|
|
}
|
|
|
|
|
return new Json(results);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Selectable> nodes() {
|
|
|
|
|
List<Selectable> nodes = new ArrayList<Selectable>(getSourceTexts().size());
|
|
|
|
|
for (String string : getSourceTexts()) {
|
|
|
|
|
nodes.add(new Json(string));
|
|
|
|
|
}
|
|
|
|
|
return nodes;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|