I am developing an application which shows a image from a site on button click.
I learned that concept and did it. But now the problem is on each day image changes on that site and i want to display that new image.
So how can i get the url for that new image?
That site has only one image so i hope if this helps for the solution because i am not getting answer for this over internet.
You can visit site to be clear. If any doubt so please ask in comments and please don't select it as off topic as its related to programming.
Asked
Active
Viewed 141 times
1
3 Answers
3
Parse it from that html page source. You can use Jsoup
String webUrl = "http://www.yoursite.com/";
Document doc = Jsoup.connect(webUrl).get();
Elements element = doc.getElementsByClass("header");
String elementText = element.text();

intrepidkarthi
- 3,104
- 8
- 42
- 75
-
Yes it will work in Android - remember to run it on a non-UI thread though :-) – Darwind Jul 11 '14 at 08:53
-
I think its great but tell me that to use it i just need to add jar file of it to my library and use this code right? – ALOK Jul 11 '14 at 08:59
-
Exactly. Add the library and use it. – intrepidkarthi Jul 11 '14 at 09:13
-
Ok so atlast i did it. I think this Jsoup is equal to DOM in javascript. Thank You very much. – ALOK Jul 11 '14 at 11:15
0
You should parse a XML RSS feed. For parsing XML RSS feed you need to use the 'xmlParser' of JSoup.
You want to get the image URLs. The image URLs are in the 'enclosure' tag with attribute 'url'. They is no 'img' tag in the RSS feed. So, you need to read the 'enclosure' tag and not the 'img' tag. I am attaching the code below to pull the image URLs. This code has been tested by me. Let me know in case of any issues.
String url = "http://www.uefa.com/rssfeed/news/rss.xml";
Document doc = Jsoup.connect(url).parser(Parser.xmlParser()).ignoreContentType(true).get();
for (Element x : doc.getElementsByTag("enclosure")) {
System.out.println(x.attr("url"));
}

Laxmeena
- 780
- 2
- 7
- 28
0
You Should parse RSS feed from this url http://apod.nasa.gov/apod.rss for parsing RSS you can use sax parser You can see this link to use the sax parser http://samir-mangroliya.blogspot.com/p/android-sax-parser.html hope can help you

Danang Kukuh
- 57
- 1
- 9