How can I parse HTML tag into Window on android?
I have an HTML tag as below:
<b>Title</b>
<i>Description</i>
I would like to parse this to window without using webview. How could I do so? please give me some suggestion.
var win = Ti.UI.createWindow({
fullscreen: false
});
win.open();
The result would be:
Title
Description
3 Answers
-
As scraping web pages can be resource-intensive, if it were me, I would write a web service running on a web server that would retrieve the data for the mobile app, returning the data in json format.
Other people may have alternative views on this however.
-
I am working with a client that would rather not introduce a server layer at this juncture. Has anybody found a solution for this?
-
I don't know where you are with this, but I was able to put together a function that pulls content from a particular div on a web site by class:
//Pull HTML content from div tag function getDivContent(url,className,element) { var client = Ti.Network.createHTTPClient(); //open url client.open('GET', url); client.onload = function(){ //get content of url in string var doc = this.responseText; //create RegEx expresison to search for div tags var pattern = new RegExp('<div class=\"' + className + '\">[\\s\\S]*?<\/div>'); var content = "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" /></head><body>" + pattern.exec(doc) + "</body>"; Ti.API.info('Store: '+ content); //replace webview content element.html = content; } client.send(); }
I then can reference it like so in my ui.js:
var aboutLabelDescription = Titanium.UI.createWebView({ width:'90%', html:'', top:20, height:'95%', borderWidth:10, borderColor:'#fff', borderRadius:15 }); getDivContent('http://pianocreations.com/about/','entry',aboutLabelDescription);
Just a note that this script may break if you have nested divs within your divs on the html page that you are referencing.