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.
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();
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"));
}
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
Related
I Want to get src value from html img tag .
by chrome and inside of inspect element i can see value of src ,but when i parse it with jsoup library, src has no value , here's my code :
document = Jsoup.connect("http://estelam.rahvar120.ir/index.jsp?
pageid=2371666&p=1").userAgent(USERAGENT).method(Connection.Method.GET)
.execute().parse();
Element element = document.select("img[id=capimg]").first(); //img
tag element
String absoluteUrl = element.absUrl("src"); // absoluteUrl = ""
String srcValue = element.attr("src"); // srcValue = ""
the website isn't reachable from other countries, but where I want to parse from html is :
<img id="capimg" alt="Enter Captcha :"
src="" width="200" height="60">
The Problem is that jsoup get html content right before javascript set src value, What Should I Do ?
Welcome to SO!
The problem you are facing is not resolvable with Jsoup because Jsoup is a HTML parser not a browser. And since it's not a browser, any content rendered by javascript will not be rendered with Jsoup.
What you need is another tool that simulates web browser such as Selenium
There are multiple way to do this.
Use Selenium to handle page retrieval and scraping.
Use Selenium to get the dynamic pages and use JSoup to parse and scrape the content.
I personally recommend 2nd approach because I am more comfortable using Jsoup to scrape.
I am creating an android application. I am getting the response from server in json format. I ma parsing the json response. When I get the content it may contain image or video link. How can I check whether image or video link is present in the content and download the corresponding image or video and display it in my application. I am aware f downloading images and displaying them, but I am not aware of how to check for the link.
My response is in the following format:
<p class='para-inside-post'> cool panda <a class='handler_name' href='/#12'>#12</a> </p><img class=\"post-img-tag\" postcreatorid=\"56332edfad441746cbd15000\" src=\"https://image.jpg\" height=\"430px\" width=\"430px\">"
I am parsing the text as shown below:
postContentSplit = Html.fromHtml(content).toString();
Similarly, how can I do the same for images and videos?
All suggestions are welcome. Please help me come out of this issue.
Use Patterns in order to check url validity
Patterns.WEB_URL.matcher(potentialUrl).matches()
It will return True if URL is valid and false if URL is invalid.
I want to develop an android application which takes a particular input from the app and gives it to a website, then the website fetches the result. I want to display this result from the website and display it in the android app. I tried using xml parsing but the website is not a xml based website. The website is http://www.fastvturesults.com/ and the input is a roll number(usn number). Can anyone guide me on how to fecth the result from this site and parse it to the app.
Use JSOUP which extracts datas from website and display the result.
Document document = Jsoup.connect(url).get();
// Get the html document title
String title = document.title(); //get title
Elements description = document
.select("meta[name=description]");
// Locate the content attribute
String desc = description.attr("content");
and so on.
How can i use JSOUP to display images in Image view using the URL. Any sample code is available for that. I searched but i couldn't find out.
Please help me with any link.
Thanks.
fir make the connection with provided link then you can get the image with
imagesRec = document.select("img[src~=(?i)\\.(png|jpe?g|gif)]");
then
String imgSrcUrl = img.attr("abs:src"); // imagePath
the you will use the Picasso lib for displaying the url as image in imageView
Picasso.with(MainActivity.this).load(imgSrcUrl).into(logo);
and thats it
you would have to parse the url of the image from the tag and then put into a string or similar. this string you can then use to load your image into an imageView.
I used the tutorial listed here to parse my XML:
http://android-er.blogspot.com/2010/05/simple-rss-reader-iii-show-details-once.html
The problem I am having is when I try to read in the XML description tag all I get is this:
The "<" symbol is where the description should go. This is the feed I am reading: http://www.calvaryccm.com/rss/devos.ashx
Please help me solve my issue in getting the real text into the description. Thank you!
I just created an android project in eclipse using the code I downloaded from the site you listed above. I only made one modification to the original sources. I changed line 33 in AndroidRssReader.java to read:
URL rssUrl = new URL("http://www.calvaryccm.com/rss/devos.ashx");
The feed loads and parses fine.
The parsing error is the result of changes you made to the original sources.
If the data is html encoded, you can use one of the following methods -- or if it is unencoded, you can surround the content in CDATA tags.
Spanned spannedContent = Html.fromHtml(htmlString);
textView.setText(spannedContent, BufferType.SPANNABLE);
or
WebView webview = (WebView) findViewById(R.id.aWebView);
String htmlString = "<html><body>Some html</body></html>";
webview.loadData(htmlString, "text/html", "utf-8");
I found out that I need to wrap my RSS tags in CDATA Tags as shown here:
Writing input for .NET web services