AyncTask不会获取Instagram个人资料网址

时间:2017-08-13 21:26:27

标签: android android-asynctask

我正在开发一个应用程序,需要它来获取Instagram个人资料源代码(非API),但是当我尝试这样做时,我没有获得源代码。问题是什么?我试过其他网站,它确实有用。

08-14 02:50:50.003 1960-1960/com.mukundmadhav.instadpdownloader I/Res: Processing...
08-14 02:50:50.005 1960-2146/com.mukundmadhav.instadpdownloader D/NetworkSecurityConfig: No Network Security Config specified, using platform default
08-14 02:50:51.546 1960-1960/com.mukundmadhav.instadpdownloader W/System.err: java.lang.IllegalStateException: No successful match so far
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at java.util.regex.Matcher.ensureMatch(Matcher.java:1051)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at java.util.regex.Matcher.group(Matcher.java:342)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at com.mukundmadhav.instadpdownloader.MainActivity.butClick(MainActivity.java:31)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener.onClick(AppCompatViewInflater.java:288)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at android.view.View.performClick(View.java:5637)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at android.view.View$PerformClick.run(View.java:22429)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at android.os.Handler.handleCallback(Handler.java:751)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at android.os.Handler.dispatchMessage(Handler.java:95)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at android.os.Looper.loop(Looper.java:154)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at android.app.ActivityThread.main(ActivityThread.java:6119)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at java.lang.reflect.Method.invoke(Native Method)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
08-14 02:50:51.547 1960-1960/com.mukundmadhav.instadpdownloader W/System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)
08-14 02:50:51.548 1960-1960/com.mukundmadhav.instadpdownloader I/Choreographer: Skipped 92 frames!  The application may be doing too much work on its main thread.
package com.mukundmadhav.instadpdownloader;

import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.concurrent.ExecutionException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MainActivity extends AppCompatActivity {


    public void butClick(View view) {
        String url = "http://instagram.com/casianandews";
        Log.i("Res","Processing...");
        FetchPic fetchPic = new FetchPic();
        try {
            String res = fetchPic.execute(url).get();
            Log.i("Res",res);
        } catch (Exception e) {
            e.printStackTrace();
        }




    }

    public class FetchPic extends AsyncTask<String,Void,String> {

        @Override
        protected String doInBackground(String... urls) {
            URL urlU;
            HttpURLConnection http = null;
            String sourceCode = "";
            try {
                urlU = new URL(urls[0]);
                http = (HttpURLConnection) urlU.openConnection();
                InputStream is = http.getInputStream();
                InputStreamReader  isr = new InputStreamReader(is);
                int data = isr.read();
                while(data!=-1){
                    sourceCode += (char) data;
                    data = isr.read();
                }
                return sourceCode;

            }
            catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

    }
}

0 个答案:

没有答案