Skip to content Skip to sidebar Skip to footer

How To Display Jsoup Parsed Data

I'm trying to parse from an HTML page that only has a body and in the body is a pre tag but thats it. I need to get the info from it and put it in my android app that is using phon

Solution 1:

You could try like this.

try {
        Document doc = Jsoup.connect(url).get();
        Element element = doc.select("input[name=username]").first();
        String get_value = element.attr("value");
        Log.e(Tag, get_value);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        Log.e(Tag, e.toString());
    }

if the html is like:

<........
 ...........>
 <........>
<input name='username' value='fantastic' type='text' .... />
<........
 ...........>
 <........>

the output will be fantastic

Edited

for your case:

new Thread( new Runnable() {
    @Override
    public void run() {
       try {
           Document doc = Jsoup.connect(url).get();
           Element element = doc.select("body").first();
           String get_value = element.text();
           Log.e(Tag, get_value);
       } catch (Exception e) {
           // TODO Auto-generated catch block
           Log.e(Tag, e.toString());
       }
     }
   }).start();

N.B: i have not run this code. but u should try this.

how to use it:

public class MainActivity extends FacebookActivity {
    private TextView textview;
    private String get_value;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    textview = (TextView)findViewById(R.id.your_textview_id);

    new Thread( new Runnable() {
         @Override
         public void run() {
            try {
                // marked for your use
                Document doc = Jsoup.connect(url).get();
                Element element = doc.select("body").first();
                get_value = element.text();
                // marked for your use

                textview.setText(get_value);

                Log.e(Tag, get_value);
            } catch (Exception e) {
                // TODO Auto-generated catch block
                Log.e(Tag, e.toString());
            }
          }
        }).start();

   // textview.setText(get_value);

}
}

Post a Comment for "How To Display Jsoup Parsed Data"