1

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.

ngrashia
  • 9,869
  • 5
  • 43
  • 58
ALOK
  • 553
  • 6
  • 17

3 Answers3

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
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