使用Jsoup选择器的我的Java代码在运行以下内容时返回null(Toast显示为'0'):
String vidLink = "https://www.youtube.com/results?search_query=adele+hello";
Document searchResultsPage = pageLoadLooper(vidLink, 1);
Elements testElems = searchResultsPage.select("div.yt-lockup.yt-lockup-tile.yt-lockup-video.clearfix");
Integer Size = (Integer) testElems.size();
Toast.makeText(context, Size.toString() ,Toast.LENGTH_LONG).show();
当我在此处测试相同的选择器时,使用“https://www.youtube.com/results?search_query=adele+hello”的“查看来源”中的HTML:http://try.jsoup.org/,它会完全按预期返回。
以下是pageLoadLooper的代码:
public Document pageLoadLooper(String url, int counter) {
int maxAttempts = 10000;
int millisTimeout = 30000;
Document page = null;
try {
page = Jsoup.connect(url).timeout(millisTimeout).maxBodySize(0).get(); //max body size = no limit
return page;
}
catch (IOException e) {
// TODO Auto-generated catch block
counter++;
if (counter < maxAttempts) {
return pageLoadLooper(url, counter);
}
else {
System.out.println("page request exceeded limit");
return null;
}
}
}
任何帮助都会被理解为什么这会返回null !!