I know, there are a lot of questions on this, but no answer helped me.
Trying to parse football news from one famous ukrainian portal and put to my listview.
I parsed "news-feed" class:
class ParseTitle extends AsyncTask<Void, Void, HashMap<String, String>>{
@Override
protected HashMap<String, String> doInBackground(Void... params) {
HashMap<String, String> hashMap = new HashMap<>();
try {
Document document = Jsoup.connect("http://football.ua/england.html").get();
Elements elements = document.select(".news-feed");
for (Element element : elements){
Element element1 = element.select("a[href]").first();
hashMap.put(element.text(), element1.attr("abs:ahref"));
}
} catch (IOException e) {
e.printStackTrace();
}
return hashMap;
}
}
Use
Elements elements = document.select("article.news-feed");
Instead of
Elements elements = document.select(".news-feed");
EDIT: comparing my code to yours, I see good differences, firstly and I think more important, you accumulate the read values in a HashMap, I in a StringBuffer. Then I connect and go this way:
try {
doc = Jsoup.connect("http://football.ua/england.html").userAgent("yourPersonalizedUA").timeout(0).ignoreHttpErrors(true).get();
topicList = doc.select("article.news-feed");
for (Element topic : topicList) {
myString += topic.html();
}} catch (IOException e) { System.out.println("io - "+e); }
buffer.append(myString);
Then, if everything worked
return buffer.toString();
Presuming you've already stated at the beggining:
private Document doc;
private String myString;
private StringBuffer buffer;
private Elements topicList;
Not shure if this helps, maybe can lead into a new perspective. Have you succeeded parsing another page with your code?