jhy/jsoup · error · Selector.SelectorParseException
Could not parse query
Error message
Could not parse query '%s': unknown node type '::%s'
What it means
jsoup's node selector parser (:: syntax, e.g. ::text, ::comment, ::data, ::cdata) threw because the identifier after '::' is not one of the known node types. The Selector.SelectorParseException names the query and the unknown node type. Only a fixed set of node-type keywords is supported.
Solutions
- Use a supported node type: ::text, ::comment, ::data, ::cdata
- Fix typos in the node selector (e.g. '::coment' -> '::comment')
- Combine node selectors with subclasses if needed, e.g. '::comment:contains(foo)'
- Use Class-based selection, e.g. selectNodes(query, TextNode.class) with ::text
Example fix
// before
List<Comment> c = doc.selectNodes("div::coment", Comment.class);
// after
List<Comment> c = doc.selectNodes("div::comment", Comment.class); Defensive patterns
Strategy: validation
Validate before calling
if (!java.util.regex.Pattern.compile("::(text|comment|data|cdata)").matcher(query).find() && query.contains("::")) {
throw new IllegalArgumentException("Unknown ::node type in: " + query);
} Type guard
boolean isKnownNodeSelector(String q) { return q.matches(".*::(text|comment|data|cdata).*"); } Try / catch
try {
List<TextNode> nodes = doc.selectNodes(query, TextNode.class);
} catch (Selector.SelectorParseException e) {
log.error("Unknown node type in '{}'", query);
throw e;
} Prevention
- Restrict :: selectors to text, comment, data, cdata
- Combine node selectors with subclasses like ::comment:contains(...)
- Add selector lint tests for generated queries
When it happens
Trigger: A selector containing '::unknownType', e.g. doc.select("div::elements") or a typo like doc.select("::coment"). Parsed in QueryParser.parseNodeSelector via parseSubclass.
Common situations: Typos in node selectors; guessing at supported ::node names; porting queries written for other selector engines with different node pseudo-syntax.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Could not parse attribute query
- Could not parse nth-index
- :matchText is no longer supported. Use…
- The supplied URL, ' ', is malformed. Make sure it is an…
- You must execute the request before getting a response.
AI-assisted analysis of jhy/jsoup@9851ac5d9c (2026-09-08).
Data as JSON: /api/errors/e8c3ab18095a1971.
Report an issue: GitHub.
Appendix: source
Thrown at src/main/java/org/jsoup/select/QueryParser.java:292
left = new NodeEvaluator.InstanceType(Node.class, pseudo);
break;
case "leafnode":
left = new NodeEvaluator.InstanceType(LeafNode.class, pseudo);
break;
case "text":
left = new NodeEvaluator.InstanceType(TextNode.class, pseudo);
break;
case "comment":
left = new NodeEvaluator.InstanceType(Comment.class, pseudo);
break;
case "data":
left = new NodeEvaluator.InstanceType(DataNode.class, pseudo);
break;
case "cdata":
left = new NodeEvaluator.InstanceType(CDataNode.class, pseudo);
break;
default:
throw new Selector.SelectorParseException(
"Could not parse query '%s': unknown node type '::%s'", query, pseudo);
}
// Handle following subclasses in node context (like ::comment:contains())
Evaluator right;
while ((right = parseSubclass()) != null) {
left = and(left, right);
}
inNodeContext = false;
return left;
}
private Evaluator byId() {
String id = tq.consumeCssIdentifier();
Validate.notEmpty(id);
return new Evaluator.Id(id);
}View on GitHub (pinned to 9851ac5d9c)