nth-child(偶数)在android中使用jsoup选择器时生成ParseException?

时间:2015-07-31 07:48:48

标签: android css-selectors jsoup

例外:

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

代码:

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是div的类名 jsoup中nth-child()方法有什么问题?

nth-child()正在http://try.jsoup.org/网站中工作,但在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)

1 个答案:

答案 0 :(得分:0)

OP发现的解决方案:

  

现在它正在工作,我更新了jsuoup.jar文件(jsoup.org/packages/jsoup-1.8.2.jar)。我相信这是旧版本的问题。