[英]Unable to Parse HTML by using JSoup
我想從網站上獲取 HTML 的數據以下載 480p 的視頻。 但它不起作用。 為此,我正在使用 Async Class。 這是我的 doInBackground 方法:
@Override
protected Void doInBackground(Void... voids) {
try {
// DOWNLOAD_URL="http://topvideodownloader.com/?url=https%3A%2F%2Fwww.dailymotion.com%2Fvideo%2Fx7nctdj"
Log.i("DownloadActivity", DOWNLOAD_URL);
Connection.Response response = Jsoup.connect(DOWNLOAD_URL)
.ignoreContentType(true)
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:64.0) Gecko/20100101 Firefox/64.0")
.referrer("http://www.google.com")
.timeout(12000)
.followRedirects(true)
.execute();
Document doc = response.parse();
Log.i("DownloadActivity",doc.toString());
// title = doc.select("div.title").text();
// Log.e("Main", title);
// String atag= doc.select("a.vd-down btn btn-default btn-download").attr("href");
// matag = atag;
// Log.e("Main", matag);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
但是方法是獲取完整的 HTML。 它只獲取它的前幾行。 我也試着用
Document doc = Jsoup.connect(DOWNLOAD_URL).userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6").get();
但是用這個方法。 它甚至沒有一行。
我不知道我做錯了什么?? 請幫我。 非常贊賞
嘗試這個
class TestAsync extends AsyncTask<Void, Integer, String> {
String TAG = getClass().getSimpleName();
protected void onPreExecute() {
super.onPreExecute();
//show progress bar
}
protected String doInBackground(Void...arg0) {
try {
// DOWNLOAD_URL="http://topvideodownloader.com/?url=https%3A%2F%2Fwww.dailymotion.com%2Fvideo%2Fx7nctdj"
Document doc = Jsoup.connect(DOWN_URL)
.header("Accept-Encoding", "gzip, deflate")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0")
.maxBodySize(0)
.timeout(0)
.get();
Log.i("DownloadActivity",doc.toString());
// title = doc.select("div.title").text();
// Log.e("Main", title);
// String atag= doc.select("a.vd-down btn btn-default btn-download").attr("href");
// matag = atag;
// Log.e("Main", matag);
} catch (Exception e) {
e.printStackTrace();
}
return "success";
}
protected void onPostExecute(String result) {
super.onPostExecute(result);
if(result.equals("success"))
//stop progress bar
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.