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 {
Documentdoc= Jsoup.connect(url).get();
Elementelement= doc.select("input[name=username]").first();
Stringget_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:
newThread( newRunnable() {
@Overridepublicvoidrun() {
try {
Documentdoc= Jsoup.connect(url).get();
Elementelement= doc.select("body").first();
Stringget_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:
publicclassMainActivityextendsFacebookActivity {
private TextView textview;
private String get_value;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
textview = (TextView)findViewById(R.id.your_textview_id);
newThread( newRunnable() {
@Overridepublicvoidrun() {
try {
// marked for your useDocumentdoc= Jsoup.connect(url).get();
Elementelement= 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"