Parse HTML looking for images to download.

You must Login before you can answer or comment on any questions.

In my app I have a webView with images and CSS and it works perfectly. I have a default set of HTML, CSS, and images that live in the resources directory incase the app has no internet access when its first opened. In apps.js I have code that will download a more recent version of the HTML, and CSS. My issue is with the images because currently the the app has no idea of what to download. I was wondering if anyone has some suggestions or sample code of how to parse the HTML document looking for the <IMG> tag's source properties. I was also thinking I could add a text file on the server with a list of images to download, then download that list, and loop through it downloading each image. I dont expect many images but I expect this area of the app to be updated frequently.

Any suggestions or sample code would be greatly appreciated.

Thanks,

David

1 Answer

Accepted Answer

If you're going to be dealing with downloading the images, you may want to use YQL to scrape the page for images and download them. This will ensure that you always have the latest version of the page, and when you don't have connectivity, then you'll still have the last version to show. YQL is built in to the Titanium core. It makes it very easy to do exactly what you are trying to do.

— answered 8 months ago by Anthony Decena
answer permalink
1 Comment
  • Cool, this is exactly what I was looking for. Currently I am downloading a JSON file with all the URL's and then looping it , downloading each image. I would much rather query the HTML file, as that would ensure I dont forget to update the JSON.

    — commented 8 months ago by David Jones

Your Answer

Think you can help? Login to answer this question!