I can't parse the title and the date of each article in this page: www.multiplayer.it. I tried in this way:
protected String doInBackground(String... params) {
try {
Document doc = Jsoup.connect(BLOG_URL).get();
Elements nodeBlogStats = doc.select("div.news-col-0"); //per multiplayer.it Elements nodeBlogStats = doc.select("div.news-col-0 h3"); per ftv #comunePartINI > option
for(Element sezione : nodeBlogStats)
{
Element info = sezione.getElementsByClass("news-box-category").first();
String dataarticolo = info.getElementsByClass("news-box-date").first().text();
String titolo = info.getElementsByTag("h3").first().text();
titoli.add(titolo);
data.add(dataarticolo);
}
} catch (Exception e) {
// In caso di errore
Log.e("ERROR", "PARSING ERROR");
}
I can't understand how can i extract these two datas.
try to use it::----> very helpful i solved by this code
private class MyTask extends AsyncTask<Void, Void, ArrayList<String>> {
ArrayList<String> arr_linkText=new ArrayList<String>();
@Override
protected ArrayList<String> doInBackground(Void... params) {
Document doc;
String linkText = "";
try {
doc = Jsoup.connect("https://www.google.com/").get();
Elements links = doc.getElementsByTag("a");
for (Element el : links) {
linkText = el.attr("href");
arr_linkText.add(linkText); // add value to ArrayList
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return arr_linkText; //<< retrun ArrayList from here
}
@Override
protected void onPostExecute(ArrayList<String> result) {
// get all value from result to display in TextView
TextView textview=(TextView)findViewById(R.id.textView2);
for (String temp_result : result) {
System.out.println("links :: "+temp_result);
textview.append (temp_result +"\n");
}
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.