android无法读取所有网站源代码

时间:2017-01-27 12:51:37

标签: java android

我在android studio中使用该代码来阅读这个(" http://www.posh24.com/celebrities")网站,但它只读了它到达此页后它停止的源页面的几行字符串"



</div>
             					<div class="channelListEntry">
             				<a href="/justin_bieber">
             					<div clas
&#13;
&#13;
&#13;

这是代码

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    GetString getString = new GetString();
    String gr = null;

    try {
         gr = getString.execute("http://www.posh24.com/celebrities").get();

    } catch (InterruptedException e) {
        e.printStackTrace();
    } catch (ExecutionException e) {
        e.printStackTrace();
    }

}

  public class GetString extends AsyncTask<String,Void,String> {
    protected String doInBackground(String... params) {


        String result = "";
        URL url;
        HttpURLConnection urlConnection = null;

        try {

            url = new URL(params[0]);

            urlConnection = (HttpURLConnection) url.openConnection();

            InputStream in = urlConnection.getInputStream();

            InputStreamReader reader = new InputStreamReader(in);

            int data = reader.read();

            while (data != -1) {

                char current = (char) data;

                result += current;

                data = reader.read();
            }

            return result;

        } catch (Exception e) {

            e.printStackTrace();

        }

        return null;

    }

0 个答案:

没有答案