Nth-child (even) throws ParseException when using jsoup selector in android?

An exception:

org.jsoup.select.Selector$SelectorParseException: Could not parse query 'table:nth-child(even)': unexpected token at ':nth-child(even) 

The code:

 Document doc = Jsoup.connect(URL+params[0]).userAgent("Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.125 Safari/537.36") .referrer("http://www.google.com").get(); Elements questions= doc.select(".content-box table:nth-child(even) a"); 

content-box is the name of the div class.
What is wrong with the nth-child() method in jsoup?

nth-child() runs on the http://try.jsoup.org/ site, but makes an exception when used on Android.

Logcat:

 W/System.err(2280): org.jsoup.select.Selector$SelectorParseException: Could not parse query 'table:nth-child(even)': unexpected token at ':nth-child(even)' W/System.err(2280): at org.jsoup.select.QueryParser.findElements(QueryParser.java:170) W/System.err(2280): at org.jsoup.select.QueryParser.parse(QueryParser.java:63) W/System.err(2280): at org.jsoup.select.QueryParser.parse(QueryParser.java:37) W/System.err(2280): at org.jsoup.select.QueryParser.combinator(QueryParser.java:79) W/System.err(2280): at org.jsoup.select.QueryParser.parse(QueryParser.java:59) W/System.err(2280): at org.jsoup.select.QueryParser.parse(QueryParser.java:37) W/System.err(2280): at org.jsoup.select.Selector.<init>(Selector.java:66) W/System.err(2280): at org.jsoup.select.Selector.select(Selector.java:79) W/System.err(2280): at org.jsoup.nodes.Element.select(Element.java:255) W/System.err(2280): at com.example1.MainScreen$MyTask.doInBackground(MainScreen.java:80) W/System.err(2280): at com.example1.MainScreen$MyTask.doInBackground(MainScreen.java:1) W/System.err(2280): at android.os.AsyncTask$2.call(AsyncTask.java:288) W/System.err(2280): at java.util.concurrent.FutureTask.run(FutureTask.java:237) W/System.err(2280): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) W/System.err(2280): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) W/System.err(2280): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) W/System.err(2280): at java.lang.Thread.run(Thread.java:841) 
+5
source share
1 answer

Solution found by OP:

Now it works after I updated the jsuoup.jar file (jsoup.org/packages/jsoup-1.8.2.jar). I believe this is a problem with the old version.

0
source

All Articles