I am a newbee in Android and I am coding a news app. I did all the xml parsing stuff, for parsing title and description of news from rss feed of the news web page. And then I want to parse the news body from html and show it in a Textview. But I couldn't make it. Please help me, the html format that I am trying to parse is like this:
<div class="classname"> some text </div><p> some text</p><p> some text</p><h2> some text </h2><p> some text </p>
My question is "how can I get the whole news text with jsoup html parsing in this case?"
I searched in the internet and learned a bit of jsoup html parsing, and write some code. But I can parse only <div class="classname"> some text </div>
part of the text. Please help me to parse whole news text.
My code is here:
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView txtview = (TextView) findViewById(R.id.txtview);
new FetchText().execute();
}
private class FetchText extends AsyncTask<Void,Void,Void>{
String yazi;
@Override
protected Void doInBackground(Void... params) {
try{
org.jsoup.nodes.Document doc = Jsoup.connect("http://newswebsite.com/bla/bla").get();
Elements elementdetail = doc.select("div[class=detail-news-spot mobile-spot]");
yazi = elementdetail.text();
Elements
}catch (Exception e){
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
TextView txt_yazarlar = (TextView)findViewById(R.id.txtview);
txt_yazarlar.setText(yazi);
}
}
}