java - Android Jsoup Parsing URL for all Body Text -


situation: have been attempting parse url , retrieve information between body tags , setting in android text view.

problem: wrong and/or missing..

code:

    package jsouptutorial.androidbegin.com.jsouptutorial;      import android.support.v7.app.appcompatactivity;      import android.os.bundle;      import android.widget.textview;      import org.jsoup.jsoup;      import org.jsoup.nodes.document;      import org.jsoup.nodes.element;      import org.jsoup.nodes.textnode;      import org.jsoup.select.elements;      import java.io.file;      import java.io.ioexception;      public class mainactivity extends appcompatactivity {            @override          protected void oncreate(bundle savedinstancestate) {              super.oncreate(savedinstancestate);              setcontentview(r.layout.activity_main);              textview textout = (textview)findviewbyid(r.id.roottxtview);      //------------------something went wrong here-------------------------------              document doc;              try {                  //doc = jsoup.connect("https://stackoverflow.com/questions/45311629/android-jsoup-parsing-url-for-all-body-text").get();                  doc = jsoup.parse(new file("https://stackoverflow.com/questions/45311629/android-jsoup-parsing-url-for-all-body-text"), "utf-8");                    elements desc = doc.select("a.body");                    textout.settext((charsequence) desc);  //setting textview string                } catch (ioexception e) {                  e.printstacktrace();              }  //--------------------------------------------------------------------              }      }

you have couple of problems here:

first trying create file object url, throw ioexception. instead want use jsoup method retrieve document url

document doc = jsoup.connect("https://stackoverflow.com/questions/45311629/android-jsoup-parsing-url-for-all-body-text").get(); 

the next problem elements selection doc.select("a.body"). trying select anchor tags <a> class of body - , there none. body use doc.body()

also mentioned cricket_007 attempting network request main thread throw networkonmainthreadexception easiest way around run in asynctask, see question details.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -