简体   繁体   English

无法使用 JSoup 解析 HTML

[英]Unable to Parse HTML by using JSoup

I want to data fetch HTML from the Website to download a video of 480p.我想从网站上获取 HTML 的数据以下载 480p 的视频。 But it's not working.但它不起作用。 I am using an Async Class for this purpose.为此,我正在使用 Async Class。 Here my doInBackground Method:这是我的 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;
        }

But method is fetching the complete HTML.但是方法是获取完整的 HTML。 It fetch only first few Lines of it.它只获取它的前几行。 I also tried to fetch with我也试着用

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();

But with this method.但是用这个方法。 It fetch not even a single line.它甚至没有一行。

I dont know what i am doing wrong??我不知道我做错了什么?? Please help me.请帮我。 much appreicated非常赞赏

try this尝试这个

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM