The use of learning--hpple for third-party libraries developed by iOS

Source: Internet
Author: User

Because HTML parsing is likely to be encountered in development, HTML parsing tools are required if the data provided in the background is only HTML data, or if the app needs to get the data from the HTML in the front of the web.

About the HTML parsing library, you can read: Collect several objective-c HTML parsing libraries to understand. The following is my study of open source project coding encountered the use of hpple parsing tools, so take it out to learn and summarize.

Create a new normal project, and then I use POD integration with this hpple library to use:

Then I'm tired parsing parsing index.html files:

The main code:

1- (void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{2NSData * data = [NSData datawithcontentsoffile:@"/users/heyang/documents/xcode/object-c/third-party library hpple Learning/hppletest/hppletest/index.html"];3NSLog (@"Data:%@", data);4Tfhpple * doc =[[Tfhpple alloc] initwithhtmldata:data];5     6Nsarray * elements = [doc searchwithxpathquery:@"//a"];7     8NSLog (@"number of a nodes:%ld", elements.count);9      for(inti =0; i < Elements.count; i++) {TenTfhppleelement * E =[elements objectatindex:i]; OneNSLog (@"1:%@", [e text]);//The text inside the HTML element (the content of the first text node) ANSLog (@"2:%@", [e TagName]);//"a" -NSLog (@"3:%@", [e attributes]);//nsdictionary of HREF, class, ID, etc. -NSLog (@"4:%@", [E Objectforkey:@"href"]);//Easy access to single attribute theNSLog (@"5:%@", [E Firstchildwithtagname:@"img"]);//the first "B" Child node -NSLog (@"=========== parsing completed once ==========="); -     } -}

The printing results are:

 .- --Ten  at: $:00.251hppletest[4478:107019] 数据:<3c703ee4 b88be58d 88e4ba94 e782b9e5 a49ae5b0 b1e588b0 e8bebee4 ba86e79b aee79a84 e59cb0e7 a8bbe59f 8ee58ebf e59f8 Ee5 a283e586 85efbc8c e4bd8fe5 9ca8e4ba 86e4b880 e4b8aae5 85b7e69c 89e5be88 e5a5bde5 9cb0e790 86e4bd8d e7bdaee7 9a84e985 9 2e5ba97 efbc8ce4 bd86e698 afe6b2a1 e69c89e7 bd91e7bb 9ce6b2a1 e69c89e7 83ade6b0 b4efbc8c e68891e5 a5bde583 8fe9ab98 e58f8d E4 ba86efbc 8ce4b880 e5a4a9e5 9d90e8bd a6efbc8c e79c8be5 88b0e4ba 86e8aeb8 e5a49ae7 9a84e7be 8ee4b8bd E699afe8 89B2EFBC 8c E5A5BD e6bc82e4 baaee5a5 bde6bc82 e4baaeef bc8ce698 8ee5a4a9 e699afe5 8cbae79a 84e69c80 e4bd8ee6 b5b7e68b 94e59b9b e58d83e 4 b8a4e799 bee5a49a e7b1b3ef bc8ce5b8 8ce69c9b e4b88de8 a681e9ab 98e58f8d e4ba86e2 80a6e280 a60a2020 20203c6120687265663d2268747470733A2F2F64 6e2d636f 64696e67 2d6e6574 2d70726f64756374696f6e2d 70702e71 626f782e 6d652f62656633633537392d646339642d343633 642d6235 34662d3531646133 333931636665622e 6a706722207461726765743d 225f626c 616e6b22 20636c61 73733d22627562626c652d6d 61726b64 6f776e2d 696d6167 652d6c69 6e6b2220 72656c3d 226e6f66 6f6c6c6f 77223e0a20202020 202020203c696d67207372633d226874 7470733a 2f2f646e 2d636f64696e672d 6e65742d70726f64756374696F6E2D70 702e7162 6f782e6d 652f62656633633537392d64 6339642d343633642d623534 662d353164613333 3931636665622e6a70672220616c743d222220636c617373 3d226275 62626c65 2d6d6172 6b646f77 6e2d696d616765223e0a2020 20203c2f 613e0a20 2020203c6120687265663d2268747470733A2F2F 646e2d63 6f64696e 672d6e65 742d7072 6f647563 74696f6e 2d70702e 71626f78 2e6d652f30353330 396330352d636263 642d3466 63612d38 3632372d39313433 62323762 393232662e6a706722207461 726765743d225f62 6c616e6b 2220636c 6173733d22627562626c652d 6d61726b 646f776e 2d696d61 67652d6c 696e6b22 2072656c 3d226e6f 666f6c6c 6f77223e 0a202020 203c696d67207372633d2268747470733A2F2F64 6e2d636f 64696e67 2d6e6574 2d70726f64756374696f6e2d 70702e71 626f782e 6D652F30353330396330352d636263642d346663 612d3836 32372d3931343362 323762393232662e 6a706722 20616c74 3d222220 636c6173 733d2262 7562626c 652d6d61 726b646f 776e2d69 6d616765 223e0a20 2020203c 2f613 e0a 3c2f703e> .- --Ten  at: $:00.255hppletest[4478:107019] a node number:2 .- --Ten  at: $:00.256hppletest[4478:107019]1: .- --Ten  at: $:00.256hppletest[4478:107019]2: a2016- --Ten  at: $:00.258hppletest[4478:107019]5: {Nodeattributearray=({attributename=src; Nodecontent="https://dn-coding-net-production-pp.qbox.me/bef3c579-dc9d-463d-b54f-51da3391cfeb.jpg"; }, {AttributeName=Alt; Nodecontent=""; }, {AttributeName=class; Nodecontent="Bubble-markdown-image";    }    ); NodeName=img; Raw="";} .- --Ten  at: $:00.258hppletest[4478:107019] =========== Parse completed once =========== .- --Ten  at: $:00.258hppletest[4478:107019]1: .- --Ten  at: $:00.259hppletest[4478:107019]2: A .- --Ten  at: $:00.259hppletest[4478:107019]3: {class="Bubble-markdown-image-link"; href="https://dn-coding-net-production-pp.qbox.me/05309c05-cbcd-4fca-8627-9143b27b922f.jpg"; Rel=nofollow; Target="_blank";} .- --Ten  at: $:00.259hppletest[4478:107019]4: https://dn-coding-net-production-pp.qbox.me/05309c05-cbcd-4fca-8627-9143b27b922f.jpg .- --Ten  at: $:00.260hppletest[4478:107019]5: {Nodeattributearray=({attributename=src; Nodecontent="https://dn-coding-net-production-pp.qbox.me/05309c05-cbcd-4fca-8627-9143b27b922f.jpg"; }, {AttributeName=Alt; Nodecontent=""; }, {AttributeName=class; Nodecontent="Bubble-markdown-image";    }    ); NodeName=img; Raw="";}

Project source Code Link: Http://pan.baidu.com/s/1eSK58eY Password: g4ic

The use of learning--hpple for third-party libraries developed by iOS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.