本文整理汇总了Java中org.jsoup.select.Selector类的典型用法代码示例。如果您正苦于以下问题:Java Selector类的具体用法?Java Selector怎么用?Java Selector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Selector类属于org.jsoup.select包,在下文中一共展示了Selector类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: findElements
import org.jsoup.select.Selector; //导入依赖的package包/类
private void findElements() {
if (tq.matches("@")) {
consumeAttribute();
} else if (tq.matches("*")) {
allElements();
} else if (tq.matchesRegex("\\w+\\(.*\\).*")) {
consumeOperatorFunction();
} else if (tq.matchesWord()) {
byTag();
} else if (tq.matchesRegex("\\[\\d+\\]")) {
byNth();
} else if (tq.matches("[")) {
evals.add(consumePredicates(tq.chompBalanced('[', ']')));
} else {
// unhandled
throw new Selector.SelectorParseException("Could not parse query '%s': unexpected token at '%s'", query, tq.remainder());
}
}
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:20,代码来源:XPathParser.java
示例2: byFunction
import org.jsoup.select.Selector; //导入依赖的package包/类
private Evaluator byFunction(XTokenQueue predicatesQueue) {
for (Map.Entry<String, FunctionEvaluator> entry : FUNCTION_MAPPING.entrySet()) {
if (predicatesQueue.matchChomp(entry.getKey())) {
String paramString = predicatesQueue.chompBalanced('(', ')');
List<String> params = XTokenQueue.trimQuotes(XTokenQueue.parseFuncionParams(paramString));
if (params.get(0).startsWith("@")) {
params.set(0, params.get(0).substring(1));
return entry.getValue().call(params.toArray(new String[0]));
} else {
return null;
}
}
}
throw new Selector.SelectorParseException("Could not parse query '%s': unexpected token at '%s'", query, predicatesQueue.remainder());
}
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:18,代码来源:XPathParser.java
示例3: functionRegex
import org.jsoup.select.Selector; //导入依赖的package包/类
private void functionRegex(String remainder) {
Validate.isTrue(remainder.endsWith(")"), "Unclosed bracket for function! " + remainder);
List<String> params = XTokenQueue.trimQuotes(XTokenQueue.parseFuncionParams(remainder.substring("regex(".length(), remainder.length() - 1)));
if (params.size() == 1) {
elementOperator = new ElementOperator.Regex(params.get(0));
} else if (params.size() == 2) {
if (params.get(0).startsWith("@")) {
elementOperator = new ElementOperator.Regex(params.get(1), params.get(0).substring(1));
} else {
elementOperator = new ElementOperator.Regex(params.get(0), null, Integer.parseInt(params.get(1)));
}
} else if (params.size() == 3) {
elementOperator = new ElementOperator.Regex(params.get(1), params.get(0).substring(1), Integer.parseInt(params.get(2)));
} else {
throw new Selector.SelectorParseException("Unknown usage for regex()" + remainder);
}
}
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:18,代码来源:XPathParser.java
示例4: byAttribute
import org.jsoup.select.Selector; //导入依赖的package包/类
private void byAttribute() {
TokenQueue cq = new TokenQueue(tq.chompBalanced('[', ']')); // content queue
String key = cq.consumeToAny(AttributeEvals); // eq, not, start, end, contain, match, (no val)
Validate.notEmpty(key);
cq.consumeWhitespace();
if (cq.isEmpty()) {
if (key.startsWith("^"))
evals.add(new Evaluator.AttributeStarting(key.substring(1)));
else
evals.add(new Evaluator.Attribute(key));
} else {
if (cq.matchChomp("="))
evals.add(new Evaluator.AttributeWithValue(key, cq.remainder()));
else if (cq.matchChomp("!="))
evals.add(new Evaluator.AttributeWithValueNot(key, cq.remainder()));
else if (cq.matchChomp("^="))
evals.add(new Evaluator.AttributeWithValueStarting(key, cq.remainder()));
else if (cq.matchChomp("$="))
evals.add(new Evaluator.AttributeWithValueEnding(key, cq.remainder()));
else if (cq.matchChomp("*="))
evals.add(new Evaluator.AttributeWithValueContaining(key, cq.remainder()));
else if (cq.matchChomp("~="))
evals.add(new Evaluator.AttributeWithValueMatching(key, Pattern.compile(cq.remainder())));
else
throw new Selector.SelectorParseException(
"Could not parse attribute query '%s': unexpected token at '%s'", query, cq.remainder());
}
}
开发者ID:virjar,项目名称:sipsoup,代码行数:35,代码来源:CacheCSSFunction.java
示例5: cssNthChild
import org.jsoup.select.Selector; //导入依赖的package包/类
private void cssNthChild(boolean backwards, boolean ofType) {
String argS = tq.chompTo(")").trim().toLowerCase();
Matcher mAB = NTH_AB.matcher(argS);
Matcher mB = NTH_B.matcher(argS);
final int a, b;
if ("odd".equals(argS)) {
a = 2;
b = 1;
} else if ("even".equals(argS)) {
a = 2;
b = 0;
} else if (mAB.matches()) {
a = mAB.group(3) != null ? Integer.parseInt(mAB.group(1).replaceFirst("^\\+", "")) : 1;
b = mAB.group(4) != null ? Integer.parseInt(mAB.group(4).replaceFirst("^\\+", "")) : 0;
} else if (mB.matches()) {
a = 0;
b = Integer.parseInt(mB.group().replaceFirst("^\\+", ""));
} else {
throw new Selector.SelectorParseException("Could not parse nth-index '%s': unexpected format", argS);
}
if (ofType)
if (backwards)
evals.add(new Evaluator.IsNthLastOfType(a, b));
else
evals.add(new Evaluator.IsNthOfType(a, b));
else {
if (backwards)
evals.add(new Evaluator.IsNthLastChild(a, b));
else
evals.add(new Evaluator.IsNthChild(a, b));
}
}
开发者ID:virjar,项目名称:sipsoup,代码行数:33,代码来源:CacheCSSFunction.java
示例6: consumePredicates
import org.jsoup.select.Selector; //导入依赖的package包/类
private Evaluator consumePredicates(String queue) {
XTokenQueue predicatesQueue = new XTokenQueue(queue);
EvaluatorStack evaluatorStack = new EvaluatorStack();
Operation currentOperation = null;
predicatesQueue.consumeWhitespace();
while (!predicatesQueue.isEmpty()) {
if (predicatesQueue.matchChomp("and")) {
currentOperation = Operation.AND;
} else if (predicatesQueue.matchChomp("or")) {
currentOperation = Operation.OR;
} else {
if (currentOperation == null && evaluatorStack.size() > 0) {
throw new IllegalArgumentException(String.format("Need AND/OR between two predicate! %s", predicatesQueue.remainder()));
}
Evaluator evaluator;
if (predicatesQueue.matches("(")) {
evaluator = consumePredicates(predicatesQueue.chompBalanced('(', ')'));
} else if (predicatesQueue.matches("@")) {
evaluator = byAttribute(predicatesQueue);
} else if (predicatesQueue.matchesRegex("\\w+.*")) {
evaluator = byFunction(predicatesQueue);
} else {
throw new Selector.SelectorParseException("Could not parse query '%s': unexpected token at '%s'", query, predicatesQueue.remainder());
}
evaluatorStack.calc(evaluator, currentOperation);
//consume operator
currentOperation = null;
}
predicatesQueue.consumeWhitespace();
}
evaluatorStack.mergeOr();
return evaluatorStack.peek();
}
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:34,代码来源:XPathParser.java
示例7: findElements
import org.jsoup.select.Selector; //导入依赖的package包/类
private void findElements() {
if (tq.matchChomp("#"))
byId();
else if (tq.matchChomp("."))
byClass();
else if (tq.matchesWord())
byTag();
else if (tq.matches("["))
byAttribute();
else if (tq.matchChomp("*"))
allElements();
else if (tq.matchChomp(":lt("))
indexLessThan();
else if (tq.matchChomp(":gt("))
indexGreaterThan();
else if (tq.matchChomp(":eq("))
indexEquals();
else if (tq.matches(":has("))
has();
else if (tq.matches(":contains("))
contains(false);
else if (tq.matches(":containsOwn("))
contains(true);
else if (tq.matches(":matches("))
matches(false);
else if (tq.matches(":matchesOwn("))
matches(true);
else if (tq.matches(":not("))
not();
else if (tq.matchChomp(":nth-child("))
cssNthChild(false, false);
else if (tq.matchChomp(":nth-last-child("))
cssNthChild(true, false);
else if (tq.matchChomp(":nth-of-type("))
cssNthChild(false, true);
else if (tq.matchChomp(":nth-last-of-type("))
cssNthChild(true, true);
else if (tq.matchChomp(":first-child"))
evals.add(new Evaluator.IsFirstChild());
else if (tq.matchChomp(":last-child"))
evals.add(new Evaluator.IsLastChild());
else if (tq.matchChomp(":first-of-type"))
evals.add(new Evaluator.IsFirstOfType());
else if (tq.matchChomp(":last-of-type"))
evals.add(new Evaluator.IsLastOfType());
else if (tq.matchChomp(":only-child"))
evals.add(new Evaluator.IsOnlyChild());
else if (tq.matchChomp(":only-of-type"))
evals.add(new Evaluator.IsOnlyOfType());
else if (tq.matchChomp(":empty"))
evals.add(new Evaluator.IsEmpty());
else if (tq.matchChomp(":root"))
evals.add(new Evaluator.IsRoot());
else // unhandled
throw new Selector.SelectorParseException("Could not parse query '%s': unexpected token at '%s'", query,
tq.remainder());
}
开发者ID:virjar,项目名称:sipsoup,代码行数:59,代码来源:CacheCSSFunction.java
示例8: byAttribute
import org.jsoup.select.Selector; //导入依赖的package包/类
private Evaluator byAttribute(XTokenQueue cq) {
cq.matchChomp("@");
String key = cq.consumeToAny("=", "!=", "^=", "$=", "*=", "~="); // eq, not, start, end, contain, match, (no val)
Validate.notEmpty(key);
cq.consumeWhitespace();
Evaluator evaluator;
if (cq.isEmpty()) {
if ("*".equals(key)) {
evaluator = new XEvaluators.HasAnyAttribute();
} else {
evaluator = new Evaluator.Attribute(key);
}
} else {
if (cq.matchChomp("=")) {
String value = chompEqualValue(cq);
//to support select one class out of all
if (key.equals("class")) {
String className = XTokenQueue.trimQuotes(value);
if (!className.contains(" ")) {
evaluator = new Evaluator.Class(className);
} else {
evaluator = new Evaluator.AttributeWithValue(key, className);
}
} else {
evaluator = new Evaluator.AttributeWithValue(key, XTokenQueue.trimQuotes(value));
}
} else if (cq.matchChomp("!="))
evaluator = new Evaluator.AttributeWithValueNot(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));
else if (cq.matchChomp("^="))
evaluator = new Evaluator.AttributeWithValueStarting(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));
else if (cq.matchChomp("$="))
evaluator = new Evaluator.AttributeWithValueEnding(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));
else if (cq.matchChomp("*="))
evaluator = new Evaluator.AttributeWithValueContaining(key, XTokenQueue.trimQuotes(chompEqualValue(cq)));
else if (cq.matchChomp("~="))
evaluator = new Evaluator.AttributeWithValueMatching(key, Pattern.compile(XTokenQueue.trimQuotes(chompEqualValue(cq))));
else
throw new Selector.SelectorParseException("Could not parse attribute query '%s': unexpected token at '%s'", query, chompEqualValue(cq));
}
return evaluator;
}
开发者ID:zongtui,项目名称:zongtui-webcrawler,代码行数:46,代码来源:XPathParser.java
示例9: select
import org.jsoup.select.Selector; //导入依赖的package包/类
/**
* Find elements that match the {@link Selector} CSS query, with this element as the starting context. Matched elements
* may include this element, or any of its children.
* <p>
* This method is generally more powerful to use than the DOM-type {@code getElementBy*} methods, because
* multiple filters can be combined, e.g.:
* </p>
* <ul>
* <li>{@code el.select("a[href]")} - finds links ({@code a} tags with {@code href} attributes)
* <li>{@code el.select("a[href*=example.com]")} - finds links pointing to example.com (loosely)
* </ul>
* <p>
* See the query syntax documentation in {@link org.jsoup.select.Selector}.
* </p>
*
* @param cssQuery a {@link Selector} CSS-like query
* @return elements that match the query (empty if none match)
* @see org.jsoup.select.Selector
* @throws Selector.SelectorParseException (unchecked) on an invalid CSS query.
*/
public Elements select(String cssQuery) {
return Selector.select(cssQuery, this);
}
开发者ID:cpusoft,项目名称:common,代码行数:24,代码来源:Element.java
示例10: selectFirst
import org.jsoup.select.Selector; //导入依赖的package包/类
/**
* Find the first Element that matches the {@link Selector} CSS query, with this element as the starting context.
* <p>This is effectively the same as calling {@code element.select(query).first()}, but is more efficient as query
* execution stops on the first hit.</p>
* @param cssQuery cssQuery a {@link Selector} CSS-like query
* @return the first matching element, or <b>{@code null}</b> if there is no match.
*/
public Element selectFirst(String cssQuery) {
return Selector.selectFirst(cssQuery, this);
}
开发者ID:SpoonLabs,项目名称:astor,代码行数:11,代码来源:Element.java
示例11: select
import org.jsoup.select.Selector; //导入依赖的package包/类
/**
* Find elements that match the {@link Selector} query, with this element as the starting context. Matched elements
* may include this element, or any of its children.
* <p/>
* This method is generally more powerful to use than the DOM-type {@code getElementBy*} methods, because
* multiple filters can be combined, e.g.:
* <ul>
* <li>{@code el.select("a[href]")} - finds links ({@code a} tags with {@code href} attributes)
* <li>{@code el.select("a[href*=example.com]")} - finds links pointing to example.com (loosely)
* </ul>
* <p/>
* See the query syntax documentation in {@link org.jsoup.select.Selector}.
*
* @param query a {@link Selector} query
* @return elements that match the query (empty if none match)
* @see org.jsoup.select.Selector
*/
public Elements select(String query) {
return Selector.select(query, this);
}
开发者ID:gumulka,项目名称:JabRefAutocomplete,代码行数:21,代码来源:Element.java
注:本文中的org.jsoup.select.Selector类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论