Parsing poorly written HTML in Appcelerator Titanium

I am trying to get some values ​​from a small piece of HTML in Titanium. I tried to use this library: https://gist.github.com/bob-sims/4406293 , as was said in another question ( HTML Parser for Titanium Mobile ), but I just can't get anything. The fact that it has no documentation at all and that I'm new to Titanium probably does not help.

The html comes from this page: http://www.ctt.pt/feapl_2/app/open/objectSearch/cttObjectSearch.jspx?showResults=true&lang=01&pesqObjecto.objectoId=RD057055721PT , and I'm trying to get the values: <tr id="object_RD057055721PT" class="object"> and <tr id="details_0" class="detailsDiv detailsHide"> and this is the code I wrote:

 var select = require('lib/soupselect').select, htmlparser = require('lib/htmlparser'); var handler = new htmlparser.DefaultHandler(function(err, dom) { if (err) { alert('Error: ' + err); } else { Ti.API.info("dom" + dom); var body = select(dom, 'meta[property="og:object_RD057055721PT"]'); rows.forEach(function(body) { Ti.API.info(body.children[0].data) }); var rows = select(dom, 'div.row'); Ti.API.info("rows: " + rows) rows.forEach(function(row) { Ti.API.info(row.children[0].data) }); } }); function renderXML() { var httpResponse = this.responseText; var parser = new htmlparser.Parser(handler); parser.parseComplete(httpResponse); }; var xhr = Ti.Network.createHTTPClient({ onload : renderXML, onerror : errorMessage, }) xhr.open("GET", "http://www.ctt.pt/feapl_2/app/open/objectSearch/cttObjectSearch.jspx?showResults=true&lang=01&pesqObjecto.objectoId=RD057055721PT"); xhr.send(); 

But all the output I get from this is:

dom [object Object], [object Object], [object Object], [object Object], [object Object]

+4
source share
1 answer

Try using YQL , it will be better versed in unknown HTML and gives a good JSON response.

0
source

All Articles