筆記目標(biāo):
1.練習(xí)使用Jsoup的相關(guān)功能
2.練習(xí)使用AsyncTask異步任務(wù)
3.復(fù)習(xí)Android相關(guān)知識(shí)點(diǎn)
工具:
1.MyEclipse + AndroidStudio
下面貼出代碼:
import java.io.IOException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
public class Test {
private static String BASE_URL = "http://www.xxx.xxx";// 主頁(yè)
private static String DETAILS_URL = "123.htm";// 詳細(xì)頁(yè)
private static int currentPageNum = 1;// 當(dāng)前頁(yè)
private static int totalPageNum = 0;// 總頁(yè)數(shù)
private static int resCount = 0;// 總資源數(shù)
private static String imageSrc = "";// 圖片地址
public static void main(String[] args) {
try {
Document document = Jsoup.connect(
BASE_URL + "/" + TYPE.anime + "/" + DETAILS_URL + "/"
+ currentPageNum).get();
totalPageNum = document.select("div #page-links").select("a")
.size() + 1;
for (int i = currentPageNum; i <= totalPageNum; i++) {
String fullUrl = BASE_URL + "/" + TYPE.hentai + "/"
+ DETAILS_URL + "/" + currentPageNum;
Document doc = Jsoup.connect(fullUrl).get();
int size = doc.select("div .post").select("p").select("a")
.size();
resCount += size;
for (int j = 0; j < size; j++) {
imageSrc = doc.select("div .post").select("p a img").get(j)
.attr("src");
System.out.println(imageSrc);
}
currentPageNum++;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}