Getting Data From Website Using Jsoup?
Trying to practice and get info from website using Jsoup not the website API. My code does not have an error but the text field is not changing. It just shows me a blank space. How
Solution 1:
The problem is lying here:
@OverrideprotectedvoidonPostExecute(Void feed) {
String ankosh = document.attr("href");
text.setText(ankosh);
}
The document
variable doesn't have an attribute called href
. This is why the ankosh
variable is empty.
Instead try this: (I suppose the main news if the first div with fc-item__content class in the document).
Element mainNewsDiv = document.select("div.fc-container--rolled-up-hide.fc-container__body > div:nth-child(1) > ul > li > div > div > div.fc-item__content").first();
if (mainNewsDiv == null) {
// Main news not found...
} else {
text.setText(mainNewsDiv.text());
}
One last note, you should avoid Jsoup.connect
for loading the document. Internally, it uses the URL
class which is notoriously slow. Use Volley instead. Please see this sample code showing the use of Volley and Jsoup.
Post a Comment for "Getting Data From Website Using Jsoup?"