ios - Parse HTML in objective C -


i've parse html ios app. read on web should use xpath , found library tfhpple. see library uses xpathquery

<!doctype "html"> <html>        <head>                 <meta property="og:site_name" content="sito 4"/>         <meta property="og:title" content="home"/>         <meta name="viewport" content="width=320" />         <meta name="keywords" content="mobile website,microsite, mobdis,iphone,android" />         <meta name="description" content="amazingly designed using mobdis.com" />         <meta http-equiv="content-type" content="text/html; charset=utf-8" />         <meta name="format-detection" content="telephone=no" />         <title>sito 4/home</title>          <!--[if (!ie)|(gte ie 8)]><!--> <link href="http://cdn2.mobdis.me/assets/publish-3.4-datauri.css" media="screen" rel="stylesheet" type="text/css" /> <!--<![endif]--> <!--[if lte ie 7]> <link href="http://cdn2.mobdis.me/assets/publish-3.4.css" media="screen" rel="stylesheet" type="text/css" /> <![endif]-->           <script type="text/javascript"></script>         <style type="text/css">             body{                 background-color: black;             }         </style>      </head>     <body>           <div id='processingscreen' style="width:320px;height:417px;background-color:rgb(0, 0, 128)"><img alt="publish_loading" src="http://cdn2.mobdis.me/pro_images/publish_loading.gif" style="max-width:100%;max-height:100%;" />         </div>          <div data-role="page" id="home" data-id="94568">               <div data-role="content" id="area" class="canvas" style="width:320px;height:417px;background-color:rgb(0, 0, 128)">                  <div id="text-1" data-name="text-1" class="drselement drsmovehandle unselectable parentdef" data-content="text" style="width: 320px; height: 50px; top: 0px; left: 0px; z-index: 1; overflow: visible; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; -webkit-box-shadow: rgb(255, 255, 255) 0px 2px 0px inset; "><div style="width: 320px; height: 50px; background-color: transparent; border-color: rgb(112, 150, 171); border-width: 2px; border-style: none none solid; border-top-left-radius: 5px; border-top-right-radius: 5px; border-bottom-right-radius: 5px; border-bottom-left-radius: 5px; background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(rgb(181, 221, 242)), to(rgb(181, 221, 242))); " class="txtdef childdef editable" data-pageid="" data-pageurl="" data-exlink="" data-transition="0" id="text-1_content" title="text-1" data-allborderradius="unchecked"><div>     &nbsp;</div> <div>     <span style="color:#ffffff;"><span style="font-family: futura; "><span style="font-size: 26px; "><span style="text-shadow: rgba(0, 0, 0, 0.59375) 1px 1px 2px; "><strong>sito 4</strong></span></span></span></span></div> </div></div><div id="image-1" data-name="image-1" class="drselement drsmovehandle unselectable parentdef" data-content="image" style="width: 320px; height: 169px; top: 48px; left: 0px; z-index: 2; " data-src="assets/promozioni.png"><img src="http://cdn2.mobdis.me/uploads/73005/original.png?1375193775" style="width: 320px; height: 169px; " data-pageid="" data-pageurl="" data-exlink="" data-transition="0" id="image-1_content" title="image-1" class="childdef"></div><div id="text-2" data-name="text-2" class="drselement drsmovehandle unselectable parentdef" data-content="text" style="width: 320px; height: 100px; top: 277px; left: 0px; z-index: 3; overflow: visible; "><div style="width: 320px; height: 100px; " class="txtdef childdef editable" data-pageid="" data-pageurl="" data-exlink="" data-transition="0" id="text-2_content" title="text-2"><div>     <span style="color:#ffffff;"><span style="font-size: 20px; "><strong>complimenti hai ottenuto una fantastica promozione!</strong></span></span></div> </div></div>             <div id="text-3" data-name="text-3" class="drselement drsmovehandle unselectable parentdef" data-content="text" style="width: 320px; height: 65px; top: 332px; left: 0px; z-index: 4; overflow: visible; "><div style="width: 320px; height: 65px; " class="txtdef childdef editable" data-pageid="" data-pageurl="" data-exlink="" data-transition="0" id="text-3_content" title="text-3"><div style="text-align: left; ">     <span style="font-size:12px;"><span style="color: rgb(255, 255, 255); ">scadenza: 29 ago 2013</span></span></div> </div></div>             </div>           </div>                     <div id="divads"><a href="http://www.mobdis.com" target="_blank"><img alt="banner" src="http://cdn2.mobdis.me/pro_images/banner.png" style="display:inline;max-width:100%;" /></a></div>                      <div id="divbrowseralert">the current version of browser not supported yet. ensure full functionality, recommend using apple safari or google chrome.<br/>                     <button onclick="dismissunsupportedbrowser('')">dismiss</button>                      <!--<button onclick=window.location = "";">redirect</button>-->                  </div>                  <script type="text/javascript">                  </script>             <script type="text/javascript">             var mpq = [];             mpq.push(["init", '5fed56e1e4a85990c0fb6ff5294d2d42']);             (function(){var b,a,e,d,c;b=document.createelement("script");b.type="text/javascript";b.async=true;b.src=(document.location.protocol==="https:"?"https:":"http:")+"//api.mixpanel.com/site_media/js/api/mixpanel.js";a=document.getelementsbytagname("script")[0];a.parentnode.insertbefore(b,a);e=function(f){return function(){mpq.push([f].concat(array.prototype.slice.call(arguments,0)))}};d=["init","track","track_links","track_forms","register","register_once","identify","name_tag","set_config"];for(c=0;c<d.length;c++){mpq[d[c]]=e(d[c])}})();             mpq.track("project_id-13003");             mpq.name_tag('mobdis');         </script>                  <div id="scriptimports">             <script src="http://cdn2.mobdis.me/assets/jq-3.4.js" type="text/javascript"></script>              <script src="http://cdn2.mobdis.me/assets/publish-3.4.js" type="text/javascript"></script>             <script src="http://cdn2.mobdis.me/assets/jqm-3.4.js" type="text/javascript"></script>       <!--   -->              <script type="text/javascript">                 var root = "http://sito4.mobdis.co/";                 var cdn_link = "http://cdn2.mobdis.me/";                  var require_passcode = false;                  var showwatermark = false;                 var shownone = false;               </script>          </div>          <div id="divautho" class="autho_56930"></div>           <div id="restrictmode" class="divbasic"></div>         <noscript style="color:red;font-size:1em;top:0px;left:0px;position:absolute;display:block;background: #363636;color:#fbb041;height:100%;text-align:center;">javascript disabled in browser.<br /> please enable javascript.</noscript>     </body> </html> 

i'm interesting in 2 information html:

  • this <title>sito 4/home</title>

  • this <span style="color: rgb(255, 255, 255); ">scadenza: 29 ago 2013</span>

for wrote code:

- (void)loaddatafromhtml {     nsurl *url = [nsurl urlwithstring:stringurl];     nsdata *data = [nsdata datawithcontentsofurl:url];      tfhpple *parser = [tfhpple hpplewithhtmldata:data];      nsstring *xpathquerystringtitle = @"//title";     nsarray *nodes = [parser searchwithxpathquery:xpathquerystringtitle];      nsmutablearray *dataarray = [[nsmutablearray alloc]initwithcapacity:0];     (tfhppleelement *element in nodes) {         htmldata *htmldata = [[htmldata alloc]init];         [dataarray addobject:htmldata];         htmldata.title = [[element firstchild]content];         htmltitle = htmldata.title;         htmltitle = [htmltitle substringtoindex:6];         htmltitle = [htmltitle stringbyreplacingoccurrencesofstring:@" " withstring:@""];     } } 

(based on tutorial: http://www.raywenderlich.com/14172/how-to-parse-html-on-ios)

now question how can find second information need? should made nsstring obtain second information? can me solve problem? thank you

i solved issue using firebug. opened page firefox , opened firebug, selected row where'd information need clicked on right button of mouse , choose "copy xpath" , paste in app , it's working!

thank suggestion!


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -