`

How to Parse HTML

阅读更多
http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/

Post Pic
[iPhone Development] How to Parse HTML
On 02.24.10, In code, iphone development, by kiichi

A few weeks ago, I was looking for a simple parser for html in iPhone because I just need to scrape a couple of webpages to get the contents. I found a nice wrapper on this posting, and it’s called hpple. Simple steps to use the library.

Include and Link libxml2

  •    1. Expand Targets
  •    2. Double Click on your project name
  •    3. Select All Configuration
  •    4. Search for Header Search Path
  •    5. Add this line below with recursive option
  •       ${SDKROOT}/usr/include/libxml2
  •    6. Search for Other Linker Flag
  •    7. Add this line below
  •       -lxml2


See screenshots below

html_include



html_linking





Download Source Codes

git clone git://github.com/topfunky/hpple.git

Then drag and drop following source codes

  • TFHpple.h
  • TFHpple.m
  • TFHppleElement.h
  • TFHppleElement.m
  • XPathQuery.h
  • XPathQuery.m


That’s it. Let’s write some codes.

// Don't forget
 // #import "TFHpple.h"
 NSData *htmlData = [[NSString stringWithContentsOfURL:[NSURL URLWithString: @"http://www.objectgraph.com/contact.html"]] dataUsingEncoding:NSUTF8StringEncoding];
 TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
 NSArray *elements  = [xpathParser search:@"//h3"]; // get the page title - this is xpath notation
 TFHppleElement *element = [elements objectAtIndex:0];
 NSString *myTitle = [element content];
 NSLog(myTitle);
 [xpathParser release];
 [htmlData release];


XCode Project Download

Donwnload the complete project file is available here.
分享到:
评论

相关推荐

    Beginning App Development with Parse and PhoneGap 无水印pdf 0分

    Beginning App Development with Parse and PhoneGap teaches you how to start app development with Parse and PhoneGap: free and open source software. Using the building block languages of the web--HTML, ...

    web scraping with python collecting more data from the modern web 2nd

    Learn how to parse complicated HTML pages Traverse multiple pages and sites Get a general overview of APIs and how they work Learn several methods for storing the data you scrape Download, read, and ...

    go系统编程(英文版)

    order to parse the command-line arguments and options of a Go program. Additionally, you will learn how to delete, rename, and move files as well as how to traverse directory structures the Go way. ...

    Python Web Scraping - Second Edition .azw3电子书下载

    Find out how to parse JavaScript-dependent websites Interact with forms and sessions About the Author Katharine Jarmul is a data scientist and Pythonista based in Berlin, Germany. She runs a data ...

    UE(官方下载)

    The purpose of this power tip is to teach you how to customize the existing HTML tags and create your own HTML tags. Combine All Open Files into a Single Destination File Have you ever needed to ...

    VB编程资源大全(英文源码 文件)

    RTFtoHTML.zip Convert RTF to HTML<END> 33 , CopyFile.zip Allows you to copy files to the clipboard just like Explorer<END><br>34 , Deletefile.zip How to prompt for a file to delete, and ...

    Velocity Suite 1.2.3

    In the spirit of Open Source projects such as Velocity, if you would like to contribute to this extension or have suggestions on how to improve it, please email me petethechop@gmail.com Special ...

    Qt5 3D官方教程配套示例代码

    Some examples require assimp library to parse the content. Go to http://assimp.sourceforge.net/ and build and install the assimp library. Then configure Qt3D to include assimp and run qmake && make.

    php.ini-development

    Output buffering is a mechanism for controlling how much output data ; (excluding headers and cookies) PHP should keep internally before pushing that ; data to the client. If your application's ...

    Visual C++ 编程资源大全(英文源码 表单)

    step1.zip Simple step by step article explaining how to create a modeless dialog box as child window.(21KB)<END><br>97,step2.zip Simple step by step article explaining how to create a modeless ...

    Python Cookbook, 2nd Edition

    How to Contact Us Safari® Enabled Acknowledgments Chapter 1. Text Introduction Recipe 1.1. Processing a String One Character at a Time Recipe 1.2. Converting Between Characters and ...

    python3.6.5参考手册 chm

    urllib.parse mailbox turtledemo Multi-threading Optimizations Unicode Codecs Documentation IDLE Code Repository Build and C API Changes Porting to Python 3.2 What’s New In Python 3.1 PEP ...

    yknytt-parser

    yknytt-parser是一个基于C#开发的工具,主要用于从knyttlevels.com网站上抓取游戏数据,并将这些数据转化...同时,参考提供的"knyttlevels-parse/how_to_run.csv",可以了解如何启动和配置yknytt-parser进行数据抓取。

    Python如何通过百度翻译API实现翻译功能

    '&to=' + self.toLang + \ '&salt=' + str(self.salt) + \ '&sign=' + sign try: httpClient = http.client.HTTPConnection('api.fanyi.baidu.com') httpClient.request('GET', myurl) response = ...

    PHP基础教程 是一个比较有价值的PHP新手教程!

    PHP网页文件被当作一般HTML网页文件来处理并且在编辑时你可以用编辑HTML的常规方法编写PHP。 PHP代表:超文本预处理器(PHP: Hypertext Preprocessor)。PHP是完全免费的,不用花钱,你可以从PHP官方站点...

Global site tag (gtag.js) - Google Analytics