org.seimicrawler.xpath.core.Scope Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of JsoupXpath Show documentation
Show all versions of JsoupXpath Show documentation
一个非常好用而且强大的基于xpath的html解析器。html的DOM树生成依赖Jsoup。Lexer 和 Parser基于Antlr4,支持完备的W3C XPATH 1.0标准语法,W3C规范:http://www.w3.org/TR/1999/REC-xpath-19991116。
The newest version!
package org.seimicrawler.xpath.core;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.seimicrawler.xpath.exception.XpathParserException;
/**
* @author github.com/zhegexiaohuozi [email protected]
* @since 2018/3/13.
*/
public class Scope {
private Elements context;
private boolean isRecursion = false;
private Scope parent;
private Scope(Elements context){
super();
this.context = new Elements();
this.context.addAll(context);
}
private Scope(Element context){
super();
this.context = new Elements();
this.context.add(context);
}
public static Scope create(Elements elements){
return new Scope(elements);
}
public static Scope create(Element el){
return new Scope(el);
}
public static Scope create(Scope scope){
return new Scope(scope.context()).setParent(scope);
}
public Scope setParent(Scope scope){
this.parent = scope;
return this;
}
public Scope getParent() {
return parent;
}
public void setContext(Elements context) {
this.context = context;
}
public boolean isRecursion(){
return isRecursion;
}
void recursion(){
this.isRecursion = true;
}
public void notRecursion(){
this.isRecursion = false;
}
public Elements context(){
return this.context;
}
public Element singleEl(){
if (context.size() == 1){
return context.first();
}
throw new XpathParserException("current context is more than one el,total = "+context.size());
}
}