为什么HttpURLConnection不能给我全部内容

时间:2016-12-21 18:29:00

标签: android http download httpurlconnection

我已经制作了一个应用程序,它将从youtube视频下载数据并对其进行处理,以获得视频图像和标题和视频质量,但它没有提供完整的网站数据:

 public class QualityDownload extends AsyncTask<String, Void,ArrayList> {

    @Override
    protected ArrayList doInBackground(String... urls) {
        try {
            URL url = new URL(urls[0]);
            HttpURLConnection urlConnection =(HttpURLConnection) url.openConnection();
            InputStream in = urlConnection.getInputStream();
            InputStreamReader reader = new InputStreamReader(in);
            char[] buffer = new char[128];
            String output = "";

            int a = reader.read(buffer);
            output = new String(buffer);

            while (a != -1 ){
                output += new String(buffer);
                a = reader.read(buffer);
            }
            Log.i("Status: ", output);
            ArrayList<String> Qualities = new ArrayList<String>();
            return Qualities;

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }
}

我得到了这个输出:

<!DOCTYPE html>
       <html lang="en">
         <head id="head">
           <style name="www-roboto">@font-face{font-family:'Roboto';font-style:norm<!DOCTYPE html>
       <html lang="en">
         <head id="head">
           <style name="www-roboto">@font-face{font-family:'Roboto';font-style:normal;font-weight:500;src:url(//fonts.gstatic.com/s/roboto/v15/RxZJdnzeo3R5zSexge8UUSZ2oysoEQEeKwjgmXLRnTc.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:normal;font-weight:400;src:url(//fonts.gstatic.com/s/roboto/v15/QHD8zigcbDB8aPfIoaupKOvvDin1pK8aKteLpeZ5c0A.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:italic;font-weight:500;src:url(//fonts.gstatic.com/s/roboto/v15/OLffGBTaF0XFOW1gnuHF0SwlidHJgAgmTjOEEzwu1L8.ttf)format('truetype');}@font-face{font-family:'Roboto';font-style:italic;font-weight:400;src:url(//fonts.gstatic.com/s/roboto/v15/W4wDsBUluyw0tK3tykhXEXYhjbSpvc47ee6xR_80Hnw.ttf)format('truetype');}</style><script name="www-roboto">if (document.fonts && document.fonts.load) {document.fonts.load("400 10pt Roboto", "E");document.fonts.load("500 10pt Roboto", "E");}</script>
             <script>var ytcsi = {gt: function(n) {n = (n || '') + 'data_';return ytcsi[n] || (ytcsi[n] = {tick: {},info: {}});},now: window.performance && window.performance.timing &&window.performance.now ? function() {return window.performance.timing.navigationStart + window.performance.now();} : function() {return (new Date()).getTime();},tick: function(l, t, n) {ticks = ytcsi.gt(n).tick;var v = t || ytcsi.now();if (ticks[l]) {ticks['_' + l] = (ticks['_' + l] || [ticks[l]]);ticks['_' + l].push(v);}ticks[l] = v;},info: function(k, v, n) {ytcsi.gt(n).info[k] = v;},setStart: function(s, t, n) {ytcsi.info('yt_sts', s, n);ytcsi.tick('_start', t, n);}};(function(w, d) {ytcsi.setStart('dhs', w.performance ? w.performance.timing.responseStart : null);var isPrerender = (d.visibilityState || d.webkitVisibilityState) == 'prerender';var vName = d.webkitVisibilityState ? 'webkitvisibilitychange' : 'visibilitychange';if (isPrerender) {ytcsi.info('prerender', 1);var startTick = function() {ytcsi.setStart('dhs');d.removeEventListener(vName, startTick);};d.addEventListener(vName, startTick, false);}if (d.addEventListener) {d.addEventListener(vName, function() {ytcsi.tick('vc');}, false);}w.__ytRIL = function(el) {if (!el.getAttribute('data-thumb')) {el.loadTime = ytcsi.now();}};})(window, document);</script>
           <script>if (window.ytcsi) {window.ytcsi.tick("_start", null, 'initpb');}</script>
           <script>if (window.ytcsi) {window.ytcsi.tick("_start", null, 'blz_watch_ads');}</script>
           <script>if (window.ytcsi) {window.ytcsi.tick("_start", null, 'blz_home_ads');}</script>
           <script>if (window.ytcsi) {window.ytcsi.tick("_start", null, 'blz_search_ads');}</script>

           <script type="text/javascript">
             var bootstrap_data = true;
           </script>
             <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

           <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, target-densityDpi=medium-dpi">

         <link rel="icon" href="//s.ytimg.com/yts/favicon-vflz7uhzw.ico" type="image/x-icon">
         <link rel="shortcut icon" href="//s.ytimg.com/yts/favicon-vflz7uhzw.ico" type="image/x-icon">   <link rel="apple-touch-icon-precomposed" href="//s.ytimg.com/yts/mobile/img/apple-touch-icon-144x144-precomposed-vflwq-hLZ.png" sizes="144x144">
         <link rel="apple-touch-icon-precomposed" href="//s.ytimg.com/yts/mobile/img/apple-touch-icon-114x114-precomposed-vflLGbwkc.png" sizes="114x114">
         <link rel="apple-touch-icon-precomposed" href="//s.ytimg.com/yts/mobile/img/apple-touch-icon-72x72-precomposed-vflNiFbcD.png" sizes="72x72">
         <link rel="apple-touch-icon-precomposed" href="//s.ytimg.com/yts/mobile/img/apple-touch-icon-57x57-precomposed-vflKsw8eJ.png">
         <title>YouTube</title>
         <link rel="stylesheet" href="//s.ytimg.com/yts/cssbin/mobile-nirvana-tablet-mangled-vfloxt1qd.css" id="page_css">

         </head>
         <body id="body" class="atom fusion-tn">

         <div id="player"></div>
         <div id="guide-layout-cont

这不是我想要的全部内容, 我做错了什么?

0 个答案:

没有答案