Search code examples
htmlxcodeuiwebviewlive

live content from html to html


I'm using UIWebView to display data from my organization data (publicize and legal), however, for instance, I would only want to pull specific data from the html file rather than pulling the whole URL. e.g. I want to pull the "News" section of the html and I want the user to only stay in that page, not enabling them to go into other parts of the website (e.g. home page, contact us) and allowing them to view the PDF article on the HTML file. I've asked around and read up on DOM and screen scraping, but it seem that the data pulled are stored in a database instead.

Is there any way that I can pull just the HTML "News" section with the PDF URL into my customized HTML file and that it will be updated live (maybe every 30second it will refresh and pull information from the website so that the content and list of PDF are up to date)(e.g. added in 3new article into the main website, my customize HTML file will also refresh and pull information from website and update my article list)

If anyone can point to me a specific method that allow HTML to HTML data passing (live), that will be great and I can go do more research on it. Currently very lost and confuse as it is my first time doing this. Any help/feedback will be very much appreciated :)

EDIT: For example, google map or google search. I don't want to use the whole google webpage, just taking the important thing that i want like the search result or map display.


Solution

  • This will involve quite a lot of learning on your part - you'll have to learn HTML / the DOM / JavaScript and iOS/UIWebVIew.

    Lets leave the live refresh part for now, I'll post another answer or edit to that later on. That's not going to easy either (check out my earlier posting today on background execution issues that will affect you, unless the update is only to take place in the foreground iOS Run Code Once a Day)

    You will have to do something like this. And note that I've never tried this, nor seen posting of people who have on here, but in theory it should work, but there will be a lot of learning as I've said, and lots of trial and error. Its a big task when you're not familiar with these things.

    1) Download the html page and load it in a UIWebView, but that UIWebView is hidden so the user's can't see it.

    2) When the page has loaded its dom will be accessable.

    3) You can use Javascript to access the DOM and look for the parts you want. How you inject and run the Javascript in UIWebView can be answered in a separate question (this answer will get too long if all the exact details are included).

    4) Remove the parts of the dom you are not interested in. Or use use events to make only those parts you are interested in appear, jQuery can probably help here.

    5) Display the UIWebView

    Alternatively the HTML could be saved to a file and string parsing could be used to search for the bits you are looking for and create a new text html file from it. I think this would get very messy, better to take advantage of the fact that UIWebView will parse the HTML page and create the dom for you.