code4craft / code4craft/xsoup

unexpexred SelectorParseException

Open
#43 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
474
Forks
148
PR merge metrics
No merged PRs in 30d

Description

My query is:
( //script | //*[@id] | //*[@class] | //*[@for] )
My query works on Selenium. But when I try to run the query to get a list of jsoup Elements by the following function:

	public static void normaliseHtmlDom(Document htmlDom) throws ConfigInitializationException {
		Elements elements = htmlDom.getAllElements();
		Elements ignoredElements = Xsoup.compile(ConfigUtils.getInstance().getIgnoredXPathUnion()).evaluate(htmlDom).getElements();
		for(Element element : elements) {
			if(ignoredElements.contains(element)) {
				elements.remove(element);
			}
		}
		
//		normaliseElementsByTagNames(elements);
//		normaliseElementsByAttributeNames(elements);
	}

The following Exception is thrown:
org.jsoup.select.Selector$SelectorParseException: Could not parse query '( //script | //*[@id] | //*[@class] | //*[@for] )': unexpected token at '( //script | //*[@id] | //*[@class] | //*[@for] )'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the query passed to Xsoup.compile(ConfigUtils.getInstance().getIgnoredXPathUnion()) and inspect how the selector is parsed before evaluate(htmlDom). Compare the result with the Selenium behavior; done means the reported XPath query no longer raises SelectorParseException and evaluates to the intended elements.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.