无法解析从Android动态网站的HTML标签(Couldn't parse the HTM

2019-10-22 11:22发布

我们正在努力在机器人领域关闭应用程序,因为我们需要从URL.so实时更新的详细信息,我们需要从现场site.we的HTML标记没有什么特定的region.so动力。

例如,在这个应用程序,我们从实际网址标题,并把它放在一个文本查看代码自带这里。我们正在使用JSOUP得到的值。

package com.example.poweralert.app;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Documented;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;

import android.app.ProgressDialog;
import android.provider.DocumentsContract;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.content.Intent;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.jsoup.nodes.Document;



public class PrimaryActivity extends ActionBarActivity {

private RadioGroup radioOptionGroup;
private RadioButton radiooptiobtn;
private Button btnDisplay;



/*public String loadJSONFromAsset() {
    String json = null;
    try {

        InputStream is = getAssets().open("locate.json");
        int size = is.available();
        byte[] buffer = new byte[size];
        is.read(buffer);
        is.close();
        json = new String(buffer, "UTF-8");


    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }
    return json;

}*/

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_primary);
    String title=null;
    Document document;
    try {
        document= Jsoup.connect("https://www.facebook.com/")
                .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                .referrer("http://www.google.com")
                .get();
        title=document.title();
        TextView text=(TextView)findViewById(R.id.textView);
        text.setText(title);

    } catch (Exception e) {
        e.printStackTrace();
        Log.d("tag","document");

    }

    /*List<String> formList= new ArrayList<String>();
    try {
        JSONObject jSONObject = new JSONObject(loadJSONFromAsset());
        JSONArray jsonArray = jSONObject.getJSONArray("Manali");

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jo_inside = jsonArray.getJSONObject(i);
            if (jo_inside.has("location")) {
                formList.add(jo_inside.getString("location"));
            }
        }



        ListView listView = (ListView) findViewById(R.id.listView1);
        listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, formList));


    } catch (JSONException e) {
        e.printStackTrace();
    }*/

    Button button= (Button) findViewById(R.id.btndis);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {




        }
    });
}

}

如何显示在文本view.the直播网址网站的标题上面的代码显示什么。

MYHTML

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textView"
        android:text="html text"
        android:layout_below="@+id/searchView"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginLeft="85dp"
        android:layout_marginTop="50dp" />


</RelativeLayout>

运行应用程序时,在日志中的猫也有这个

04-03 12:29:11.123  26083-26083/com.example.ipower.app D/dalvikvm﹕ Zygote::ForkAndSpecialize : 0
04-03 12:29:11.124  26083-26083/com.example.ipower.app D/dalvikvm﹕ zygote get new systemTid : 26083
04-03 12:29:11.124  26083-26083/com.example.ipower.app D/dalvikvm﹕ Late-enabling CheckJNI
04-03 12:29:11.127  26083-26083/com.example.ipower.app D/jdwp﹕ prepping for JDWP over ADB
04-03 12:29:11.127  26083-26083/com.example.ipower.app D/jdwp﹕ ADB transport startup
04-03 12:29:11.127  26083-26086/com.example.ipower.app D/dalvikvm﹕ Elevating priority from 0 to -8
04-03 12:29:11.127  26083-26087/com.example.ipower.app D/jdwp﹕ JDWP: thread running
04-03 12:29:11.130  26083-26087/com.example.ipower.app D/jdwp﹕ acceptConnection
04-03 12:29:11.130  26083-26087/com.example.ipower.app D/jdwp﹕ trying to receive file descriptor from ADB
04-03 12:29:11.143  26083-26087/com.example.ipower.app D/jdwp﹕ received file descriptor 40 from ADB
04-03 12:29:11.144  26083-26083/com.example.ipower.app D/dalvikvm﹕ zygote get thread init done
04-03 12:29:11.148  26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.148  26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.148  26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000024, flags=0x0, dataLen=0x8
04-03 12:29:11.162  26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.162  26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x17, id=0x40000025, flags=0x0, dataLen=0xC
04-03 12:29:11.170  26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.170  26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000026, flags=0x0, dataLen=0x8
04-03 12:29:11.176  26083-26087/com.example.ipower.app D/jdwp﹕ processIncoming
04-03 12:29:11.176  26083-26087/com.example.ipower.app D/jdwp﹕ handlePacket : cmd=0x1, cmdSet=0xC7, len=0x13, id=0x40000027, flags=0x0, dataLen=0x8
04-03 12:29:11.715  26083-26083/com.example.ipower.app D/jdwp﹕ sendBufferedRequest : len=0x3D
04-03 12:29:12.295  26083-26083/com.example.ipower.app D/jdwp﹕ sendBufferedRequest : len=0x47
04-03 12:29:12.464  26083-26083/com.example.ipower.app W/asset﹕ AssetManager-->addDefaultAssets CIP path not exsit!
04-03 12:29:13.130  26083-26083/com.example.ipower.app W/System.err﹕ android.os.NetworkOnMainThreadException
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1128)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:70)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection.<init>(HttpConnection.java:50)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:340)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:87)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpConnection.connect(HttpConnection.java:128)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:316)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.connect(HttpEngine.java:311)
04-03 12:29:13.139  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.sendSocketRequest(HttpEngine.java:290)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:240)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:81)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at com.example.ipower.app.MainActivity.onCreate(MainActivity.java:29)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5122)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
04-03 12:29:13.140  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
04-03 12:29:13.141  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.access$600(ActivityThread.java:162)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:107)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Looper.loop(Looper.java:194)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5371)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:525)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
04-03 12:29:13.142  26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-03 12:29:13.143  26083-26083/com.example.ipower.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
04-03 12:29:13.143  26083-26083/com.example.ipower.app I/System.out﹕ [CDS] fix other exception in HttpUrlConnection
04-03 12:29:13.143  26083-26083/com.example.ipower.app W/System.err﹕ java.io.IOException
04-03 12:29:13.143  26083-26083/com.example.ipower.app W/System.err﹕ at libcore.net.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:87)
04-03 12:29:13.143  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
04-03 12:29:13.143  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:434)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:181)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at org.jsoup.helper.HttpConnection.get(HttpConnection.java:170)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at com.example.ipower.app.MainActivity.onCreate(MainActivity.java:29)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5122)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1081)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2307)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.access$600(ActivityThread.java:162)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:107)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.os.Looper.loop(Looper.java:194)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5371)
04-03 12:29:13.144  26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
04-03 12:29:13.145  26083-26083/com.example.ipower.app W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:525)
04-03 12:29:13.145  26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
04-03 12:29:13.145  26083-26083/com.example.ipower.app W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
04-03 12:29:13.145  26083-26083/com.example.ipower.app W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)
04-03 12:29:13.171  26083-26083/com.example.ipower.app V/PhoneWindow﹕ DecorView setVisiblity: visibility = 4
04-03 12:29:14.790  26083-26083/com.example.ipower.app V/PhoneWindow﹕ DecorView setVisiblity: visibility = 0
04-03 12:29:14.919  26083-26083/com.example.ipower.app D/libEGL﹕ loaded /system/lib/egl/libEGL_mali.so
04-03 12:29:14.936  26083-26083/com.example.ipower.app D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_mali.so
04-03 12:29:14.941  26083-26083/com.example.ipower.app D/libEGL﹕ loaded /system/lib/egl/libGLESv2_mali.so
04-03 12:29:15.013  26083-26083/com.example.ipower.app D/OpenGLRenderer﹕ Enabling debug mode 0
文章来源: Couldn't parse the HTML tags from live site in android