gpt4 book ai didi

java - 无法使用 JSoup 解析 HTML

转载 作者:行者123 更新时间:2023-12-01 22:07:21 24 4
gpt4 key购买 nike

我想从网站获取 HTML 数据来下载 480p 的视频。但这不起作用。我正在使用异步类来实现此目的。这是我的 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
}
}

关于java - 无法使用 JSoup 解析 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58681820/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com