WebView Android application - how to read website content - java

Basically I am designing an webview app which would work something like this...
Pic Link : http://tinypic.com/r/2z9060n/6
I have made a webview browser application as shown in the pic. Now I want to define a mechanism using which I can crawl the webcontent and get content say marked in Red in the pic. Based on this content I wanna call another API which will show a message at the green box down.
Any help in the regard would be much appreciated.
Thanks

You can use a HTML parser such as Jsoup to parse the HTML page for the title / price of the item. Based on what the title and price are you can display a message using an overlay.
On a side note, the site is flipkart.com. You could also ask them if they have an API that they'd like to expose to you.

Related

How to enter a website and scrape text/div name/button code and save it to variable - Android Java

I am an newbie in android / java topic so thanks to you all who responds and helps me! :)
So I am looking for a specific function to my android app.
I want my app to enter website (even in the background, not in webview) and scrape (copy) button code (for example URL of the button) / OR specific text.
Regarding text (as it would be easier to explain), there are a website where texts appears:
Hello, today is <name of today's holiday>. And I want to scrape this name of today's holiday. Every visit, it is changing.
And I want to use it later in my code, so I guess we need to store it somehow (as a variable?).
So, we need to:
enter a specific URL in the background
copy specific text
store it in the app and for example, show it in the app.
Thanks all for replies!

How to know if a URL of an image is Valid using GWT?

I am using google web toolkit, and I want to enter an URL in a textbox, and display the image from this URL on the page, so I use an ArrayList to handle my images, and a VerticalPanel, to display my images. So I want to add my image to my ArrayList and panel only when the URL is valid, and the data is an image.
I tried with image.addErrorHandler(), but it's not really what I want, I don't know how to use this, to stop the add of my image. So I saw this post from stackoverflow , but I don't understand how it works...
Thank you for your help !

Get div / html element height and width server side

I would like to calculate the height and width of the main content area of a blogpost server side. This is something that needs to be done for many different websites. But mostly Wordpress sites. I need the width and height off the blogpost for an algorithm as parameters.
I could ask the user for this info, but unfortunately the people who are using this website are not technical so they have no idea how to find this information (eg in a developer tool). If the numbers are incorrect the outcome of my algorithm is most likely incorrect.
First I tried if there was a way to do this with PHP, but was not able to find it. Then I thought about using Java and then use PHP to communicate with Java again. Couldn’t find anything either.
Next step could be to let a user “select” a div or area and calculate it from there, but this would not be ideal, because you would need the user input every time you would like to make a calculation. One other problem with this would also be how to find the main content div / element first?
If I am able to find the main content div server side automatically I could load the blogpost in an iframe and calculate the width and height with jquery. But how would you find the main content div?
Anyone who has a way to solve this problem? I am kind of open to any solution without the user input.
Not going to be easy to do this server side, as you're not rendering the page.
I would suggest looking at using JavaScript to retrieve the dimensions of the Div you want, and then sending these server side from your script or from a form.
You could automate the process by triggering your JS function on page load, or trigger it using a button pressed by the user, or whatever.
For reference, you can get div height and width as follows:
var divHeight = document.getElementById('myDiv').clientHeight;
var divWidth = document.getElementById('myDiv').clientWidth;
Hope this helps.

Anchor not working in IE7 via redirect (spring-mvc, jsp)

So for this project I am doing I have a page which generates content via clickable buttons. The button posts the form to my controller and the controller acts on the button that has been clicked. To show what was changed a redirect will occur (form in the session) with an anchor included. A little piece of javascript will then go to anchor which is in the link (eg. website/add/picture#123). This works fine in pretty much every browser except Internet Explorer 7.. I found out this has to do with an input field of file type.. Because if I remove the input field, then even IE7 will nicely scroll to the anchor..
Does anyone have any idea why this behaviour occurs?
If it's unclear please tell me and I'll provide more details..
Thanks a lot,
Davey
So.. I didn't manage to solve the input type=file bug.. I suppose it's just an IE7 bug. I made a work around to put the input field on a popup. A lot of overhead but it is working pretty well now

How to set webview area upon loading a link?

Ok so I have an rss reader that links to articles. One of the sites it links to doesn't have a mobile view. I was wondering if anyone knew if it was possible to set the "zoom" and position of the view once the page is loaded? So for instance if the following link were my article... http://www.neworleanssaints.com/news-and-events/article-1/Saints-agree-to-terms-with-7th-round-pick-Sean-Canfield/cce6a9ca-eaee-4878-ad40-0b98609f7fe7
Then how could I have the view focus on the article without the user having to zoom in and scroll the the top of the article. Thanks.
I think, you have to use an anchor, which are based on the ids of the HTML code. Then, you have to pass the Id you want to stick to after the url and a #.
With your example, it would give something like that :
http://www.neworleanssaints.com/news-and-events/article-1/Saints-agree-to-terms-with-7th-round-pick-Sean-Canfield/cce6a9ca-eaee-4878-ad40-0b98609f7fe7#c1256209263986
As the div you are looking for has an id (lucky you cause they don't have all the time)
<div id="c1256209263986" class="iw_component"><div xmlns:esi="http://www.edge-delivery.org
Hope this will help you (Try to click on the link I put, this should open the page at the start of the article.)
I never tried that but have a go a this, and come back to tell me if it worked.

Categories