本规范不起作用:
String description = Pattern.compile("<div.*?>(.*?)</div>", Pattern.DOTALL).matcher(html).group(1);
本准则正在运作:
Pattern pdescription = Pattern.compile("<div.*?>(.*?)</div>", Pattern.DOTALL);
Matcher mdescription = pdescription.matcher(html);
if (mdescription.find()) {
String description = mdescription.group(1);
}
为什么我需要声明两个对象? Logcat写道:
01-09 21:33:06.741: E/AndroidRuntime(1734): FATAL EXCEPTION: Thread-150
01-09 21:33:06.741: E/AndroidRuntime(1734): java.lang.IllegalStateException: No successful match so far
01-09 21:33:06.741: E/AndroidRuntime(1734): at java.util.regex.Matcher.ensureMatch(Matcher.java:607)
01-09 21:33:06.741: E/AndroidRuntime(1734): at java.util.regex.Matcher.group(Matcher.java:358)
01-09 21:33:06.741: E/AndroidRuntime(1734): at com.ibelieve.news.SearchEngine.Baidu.GetNews(Baidu.java:45)
01-09 21:33:06.741: E/AndroidRuntime(1734): at com.ibelieve.news.MainActivity$2$1.run(MainActivity.java:52)
01-09 21:33:06.741: E/AndroidRuntime(1734): at java.lang.Thread.run(Thread.java:856)
答案 0 :(得分:0)