EzDevInfo.com

hpple

An XML/HTML parser for Objective-C, inspired by Hpricot. Computer Science and Web Education, Training, and Entertainment | Topfunky Corporation

NSString with some html tags, how can I search for tag and get the content of url

I have a NSString with some html tags, how can I search for tag and get the content of url? I'm not sure if I must use Hpple or a simple Regex expression. In both cases can I have some example?


Source: (StackOverflow)

Parsing inner HTML iteratively using Hpple parser and NSXMLParser

I have been working on school newspaper app for iPad platfrom. I am using NSXMLParser to get the titles, brief descriptions, and links for each article. In order to get HTML items from each parsed link, I decided to use Hpple parser. I think I am parsing and storing RSS items correctly, but when I try to parse HTML items from each parsed link using for loop, it tells me that I have an empty array for RSS items. However, I can display the content of RSS item holder on console. So, it is NOT empty. I will put some portion of my code and display from console. Please help me out. Due date for this project is soon. Thanks in advance.

Here is how I start loading my RSS parser (articleParser):

- (void)loadData {
    [self loadInitData];

    //[self loadDataWithLink];

}

- (void)loadInitData {
    if (sections == nil) {
        [activityIndicator startAnimating];

        NSLog(@"STARTING ARTICLE PARSER FROM MAIN URL!!!");

        Parser *articleParser = [[Parser alloc] init];
        [articleParser parseRssFeed:@"http://theaggie.org/rss/headlines.xml" withDelegate:self];
        [articleParser release];
    } else {

    }

}

And below is how I store the recieved Article items in NSMutable array called "sections". Then I used for loop to iterate over each link of parsed articles.

- (void)receivedArticleItems:(Article *)theArticle {
    if (sections == nil) {
        sections = [[NSMutableArray alloc] init];
    }
    [sections addObject:theArticle];

    NSLog(@"We recieved the article!");
    NSLog(@"Article: %@", theArticle);
    NSLog(@"What is in sections: %@", sections);

for (int i = 1; i < 5; i++) {
        NSLog(@"articleItems: %@",[sections objectAtIndex:0]);
        NSLog(@"articleItems at index 0: %@",[[[sections objectAtIndex:0] articleItems] objectAtIndex:0]);

        [self loadDataWithLink:[[[[sections objectAtIndex:0] articleItems] objectAtIndex:0] objectForKey:@"link"]];
    }
    [activityIndicator stopAnimating];
}

Below is how I used TFFHpple parser to get HTML items from each parsed link:

- (void)loadDataWithLink:(NSString *)urlString{

 NSData *htmlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];

 // Create parser
 TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];

 //Get all the cells main body
 htmlElements  = [xpathParser search:@"//div[@id='main']/div[@id='mainCol1']/div[@id='main-body']"];

 // Access the first cell
 TFHppleElement *htmlElement = [htmlElements objectAtIndex:0];

 // NSString *title = [htmlElement content];

 NSLog(@"What is in element: %@", htmlElement);

 [xpathParser release];
 //[htmlData release];
}

And this is what I am getting on the console:

2011-05-02 22:58:35.355 TheCalAggie[2443:207] Parsing started for article!
2011-05-02 22:58:35.356 TheCalAggie[2443:207] Adding story title: Students say, 'No time for books'
2011-05-02 22:58:35.356 TheCalAggie[2443:207] From the link: http://theaggie.org/article/2011/05/03/students-say-no-time-for-books
2011-05-02 22:58:35.357 TheCalAggie[2443:207] Summary: The last book managerial economics major Kiyan Parsa read for fun was The Lord of the Rings. That was in high school.
2011-05-02 22:58:35.358 TheCalAggie[2443:207] Published on: Tue, 03 May 2011 00:00:00 -0700
2011-05-02 22:58:35.359 TheCalAggie[2443:207] Parsing started for article!
2011-05-02 22:58:35.360 TheCalAggie[2443:207] Adding story title: UC Davis craft center one of largest college crafting centers
2011-05-02 22:58:35.360 TheCalAggie[2443:207] From the link: http://theaggie.org/article/2011/05/02/uc-davis-craft-center-one-of-largest-college-crafting-centers
2011-05-02 22:58:35.361 TheCalAggie[2443:207] Summary: Hidden away in the South Silo, the UC Davis Craft Center offers 10 craft studios and more than a hundred classes for students looking to learn or perfect their crafting skills.
2011-05-02 22:58:35.362 TheCalAggie[2443:207] Published on: Mon, 02 May 2011 00:00:00 -0700
2011-05-02 22:58:35.362 TheCalAggie[2443:207] We recieved the article!
2011-05-02 22:58:35.363 TheCalAggie[2443:207] Article: *nil description*
2011-05-02 22:58:35.364 TheCalAggie[2443:207] What is in sections: (
    (null)
)
2011-05-02 22:58:35.374 TheCalAggie[2443:207] articleItems: *nil description*
2011-05-02 22:58:35.375 TheCalAggie[2443:207] articleItems at index 0: {
    link = "http://theaggie.org/article/2011/05/03/peaceful-rally-held-on-campus-after-killing-of-bin-laden\n";
    pubDate = "Tue, 03 May 2011 00:00:00 -0700";
    summary = "The announcement of Osama bin Laden's death sent a wave of patriotism across the nation and UC Davis. Bin Laden was the leader of al-Qaeda - the organization allegedly behind the Sept. 11, 2001 attacks that killed over 3,000 Americans.\n";
    title = "Peaceful rally held on campus after killing of bin Laden \n";
}
2011-05-02 22:59:35.376 TheCalAggie[2443:207] Unable to parse.
2011-05-02 22:59:35.379 TheCalAggie[2443:207] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSMutableArray objectAtIndex:]: index 0 beyond bounds for empty array'
*** Call stack at first throw:

Any help will be greatly appreciated. Thanks again.


Source: (StackOverflow)

Advertisements

How to parse HTML on iPhone using TouchXML or other libraries?

I have a dirty HTML code that is loaded from a foreign server (so I can't make a json file or clean the html code). My HTML's structure is like:

<!-- SOME DIRTY HTML, CSS, JS, AND OTHER STUFF -->

<div class="pic"> ... </div>

<div class="pic" id="pic311809">

<input type="hidden" class="pic_id" name="pic_id" value="311809" />

<!-- tylko komixxy.pl -->
<div style="font-family: verdana, arial, helvetica, sans-serif; font-weight: bold; font-size: 9px;">
                                        <a rel='nofollow' href="pic/show_series/1">FFFUUU (rageman)</a>
        </div>

<h1 class="picture">Kochana babcia</h1>

<div class="infobar">
    Wrzucone 15 października 2010 o 16:03       przez <a rel='nofollow' href="/user/Astraly">Astraly</a>
    |
    <a rel='nofollow' href="http://komixxy.pl/311809/Kochana-babcia#comments">Skomentuj (23)</a>
    <!-- głosowanie przeniesione pod spód obrazka -->
</div><!-- .infobar -->


<div class="pic_image">
                <a rel='nofollow' href="http://komixxy.pl/311809/Kochana-babcia"><img src="http://staticrps.komixxy.pl/uimages/201010/1287151388_by_Astraly_500.jpg" class="pic" alt="Kochana babcia - Wnusiu, a ty jeszcze nie w szkole? Dziś mamy na 10 babciu Co ty tam majaczysz? Jesteś na wagarach!? już ja to powiem twojej mamie! Ale babciu.... Przynosisz nam wstyd! Myślisz, że nie wiem o tej ostatniej niedzieli, w której nie byłeś u komunii? ZAMKNIJ SIĘ KU**A!!!! .... Nie musisz tak krzyczeć! Powiem twojej mamie z jakim tonem odnosisz się do mnie! " /></a>          </div><!-- .pic_image -->

                <div class="source">Źródło: Kto mieszka z babcią, ten wie jak to jest ;)</div>

<!-- głosowanie i ocena -->

<div class="source">

    <div class="infobar center">

        Głosuj:

        <a rel='nofollow' href="/pic/vote/311809/up"
             onclick="votowanie(this); return false;"
             class="vote voteup iconlink"
        >
            mocne ↑         </a>

        &middot;

        <a rel='nofollow' href="/pic/vote/311809/down"
             onclick="votowanie(this); return false;"
             class="vote votedown iconlink"
        >
            słabe ↓         </a>


        <!-- DODATKOWY PRZYCISK RAPORTOWANIA DUPLIKATÓW (“BYŁO”) -->

        |

        <span class="points">
                                87% mocnych
                        </span>

        <span class="count">
                                z 1291 głosów
                        </span>

        <span class="vote_result"></span>

                    | <a rel='nofollow' href="/user/add_favorite/311809" class="favorite">Do ulubionych</a>


    </div><!-- .infobar -->

    <!-- PRZYCISK LAJKONIKA -->
    <div style="text-align: center;">
        <fb:like rel='nofollow' href="http://komixxy.pl/311809/Kochana-babcia"
                         layout="button_count"
                         show_faces="true"
                         width="130"
                         font="arial"
                         style="width: 130px;">
        </fb:like>
    </div>

    <!-- tylko komixxy.pl -->
    <a rel='nofollow' href="http://komixxy.pl/pic/show_group/311809" class="picbutton">Pokaż podobne komixxy</a>       <a rel='nofollow' href="http://komixxy.pl/przerob/311809" class="picbutton">Zrób własną wersję</a>
    <div style="clear: both;"></div>

</div><!-- .source -->



</div><!-- .pic -->

<div class="pic"> ... </div>

<div class="pic"> ... </div>

<div class="pic"> ... </div>

I want to select all <div class="pic" id="*"> by using xPath //div[@class='pic'][@id].

Here are two libraries that I used:

- Hpple
- TouchXML

As for Hpple -> it's great but I can't select innerHTML of an emelent. As for TouchXML, I use it for parsing XML and it's great. But it doesn't manage to parse dirty HTML - I get dozens of errors.

Is there a way to parse this HTML in iOS5 using TouchXML? It can be a different library, but I prefer that one.

I heard something about CTidy.h and I did as instructed but nothing's changed...


Source: (StackOverflow)

hpple : 'libxml/tree.h' file not found

When I use hpple and build, aways show " 'libxml/tree.h' file not found " error.

I have , set [Header Search Path] "${SDKROOT}/usr/include/libxml2" set [Other Linker Flag] value as "-lxml2"


Source: (StackOverflow)

TFHppleElement (Hpple), parsing HTML on iphone

I'm using Hpple and it's been great so far however I want to get all the divs inside another and that I can do. But then I am unable to further parse the contents (innerHTML, and in the source it is labelled innerHTML not innerText) asking for the elements content returns nothing as there is no text directly in that element, only child nodes/elements which then contain text.

What alternatives are there to Hpple and parsing HTML on the iPhone.


Source: (StackOverflow)

Objective C, xpath query not working

I have next html structure

<div class="item column-1">
  <h2>
    <a rel='nofollow' href="/news/1172-zimnee-21-12-2014">
      some text
    </a>
  </h2>

</div>

I want to get content of a tag, I'm using this code

NSURL *newURL = [NSURL URLWithString:@"http://mfc.mk.ua/news"];
NSData *newsData = [NSData dataWithContentsOfURL: newURL];

TFHpple *newsParser = [TFHpple hppleWithHTMLData: newsData];

NSString *newsXpathQueryString = @"//div[@class='item column-1']/h2/a";
NSArray *newsNodes = [newsParser searchWithXPathQuery: newsXpathQueryString];

NSMutableArray *newNews = [[NSMutableArray alloc] initWithCapacity: 0];

for (TFHppleElement *element in newsNodes)
{
    News *news = [[News alloc] init];

    [newNews addObject: news];

    news.title = [[element firstChild] content];

    _objects = newNews;
}

But it returning no results. If I do this:

news.title = [element objectForKey:@"href"]; 

then I'm getting results. What I doing wrong? Please help.


Source: (StackOverflow)

NDHpple query for text after child element

<span class="onShow">
   <b class="info-label">Owner description</b>
   "
   A preservation of Catholic Church art and traditions salvaged from individuals and         
   churches and schools that have closed. as well as a large collection of Bibles from 1558 
   and on, oil paintings, four working pipe organs, statuary, historic vestments from the 
   Holy Land and many other treasures of the Catholic mind and memory.
   "
   <span class="hide taLnk hvrIE6" onclick="ta.id('TOGGLE_ME_1').addClass('off');">less</span>
</span>

This code repeats throughout the html. I'm trying to grab the paragraph of text within the span. Not every one. Just the first one. I've tried:

parser.searchWithXPathQuery("//span[@class='onShow']/text()[normalize-space()]")?.first?.text

parser.searchWithXPathQuery("//span[@class='onShow']")?.first?.firstTextChild?.text

parser.searchWithXPathQuery("//span[@class='onShow']")?.first?.text

The first two returned nil and the last one returned "/n". I'm not sure what I can do to parse what I need.

EDIT: To clarify, I'm trying to grab the "A preservation of Catholic Church art and traditions...",etc paragraph.


Source: (StackOverflow)

Parse block into UITableCell

I'm using Hpple to parse HTML of a website onto my app. The parsing is working great but instead of all the contents of the tr block to be in one cell, each of the td elements in the tr block are table cells of their own. Here's what I mean. The TR Block:

<tr>
                    <td>2</td>
                    <td>down 1</td>
                    <td>1</td>
                    <td>5</td>
                    <td>Justin Bieber</td>
                    <td>What Do You Mean?</td>
                </tr>

What it looks like in the app:
enter image description here

When I want it to actually look like this: enter image description here

The code I'm using for the parsing looks like this:

 - (void)loadSongs {
// 1
NSURL *tutorialsUrl = [NSURL URLWithString:@"http://www.bbc.co.uk/radio1/chart/singles/print"];
NSData *tutorialsHtmlData = [NSData dataWithContentsOfURL:tutorialsUrl];

// 2
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];

// 3
NSString *tutorialsXpathQueryString = @"//tr/td";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];

// 4
NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in tutorialsNodes) {
    // 5
    Tutorial *tutorial = [[Tutorial alloc] init];
    [newTutorials addObject:tutorial];

    // 6
    tutorial.title = [[element firstChild] content];
   tutorial.peakPosition = ???;


}

// 8
_objects = newTutorials;
[self.tableView reloadData];
}

Source: (StackOverflow)

Get table data from html using hpple

I am trying to parse the following website so I display the data like this on iOS:

Saturday 6th September

Causeway
Bond's Glen Raceway
11:00am
RO
Two Day Meeting
Two Separate Days

An example of the website:

    <div id="main-column">
<h1>September</h1>
    <table align="center"><col width="200"><col width="150"><col width="100"><col width="120"><col width="330"><col width="300">
        <h2>Saturday 06 September</h2>
        <tr id="table1">
            <td><b>Club</b></td>
            <td><b>Venue</b></td>
            <td><b>Start Time</b></td>
            <td><b>Meeting Type</b></td>
            <td><b>Number of Days for Meeting</b></td>
            <td><b>Notes</b></td>
        </tr>
        <tr id="table2">
            <td>Causeway</td>
            <td>Bond's Glen Raceway</td>
            <td>11:00am</td>
            <td>RO</td>
            <td>Two Day Meeting,<br> Two Separate Days</td>
            <td></td>
        </tr>
        <tr id="table3">
            <td>West Waterford</td>
            <td>Ballysaggart</td>
            <td>11:00am</td>
            <td>RO</td>
            <td>Two Day Meeting,<br> One Meeting Over Two Days</td>
            <td></td>
        </tr>

So far I have managed to get all of the dates with the following code:

    -(void)loadData {

NSURL *url = [NSURL URLWithString:@"http://www.national-autograss.co.uk/september.htm"];
NSData *htmlData = [NSData dataWithContentsOfURL:url];


TFHpple *htmlParser = [TFHpple hppleWithHTMLData:htmlData];


NSString *xpathQueryString = @"//h2";
NSArray *eventNodes = [htmlParser searchWithXPathQuery:xpathQueryString];



NSMutableArray *eventDates = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in eventNodes) {

    NSString *date = [[element firstChild] content];
    [eventDates addObject:date];

}

_objects = eventDates;
[self.tableView reloadData];

}

Is the Xpath query I need for the data in the table something like //table/tr/td? I tried this and I got an immediate error of adding a nil object to an array.

Or am I better to get all of the tables as separate elements and then parse individually for the data inside?

Any help, guides or ideas would be very much appreciated.


Source: (StackOverflow)

Parse xml in Xcode with Hpple

I have some xml that looks like this:

<menu>
    <day name="monday">
        <meal name="BREAKFAST">
            <counter name="Bread">
                <dish>
                    <name>Plain Bagel
                        <info name="Plain Bagel">
                            <serving>1 Serving (90g)</serving>
                            <calories>200</calories>
                            <caloriesFromFat>50</caloriesFromFat>
                        </info>
                    </name>
                </dish>
                <dish>
                    <name>Applesauce Coffee Cake
                        <info name="Applesauce Coffee Cake">
                            <serving>1 Slice-Cut 12 (121g)</serving>
                            <calories>374</calories>
                            <caloriesFromFat>104</caloriesFromFat>
                        </info>
                    </name>
                </dish>
            </counter>
        </meal>
    </day>
</menu>

And now I am trying to get the number of tags that are under the info tag which should be three for the first info tag which has the attribute of Plain Bagel.

Like I said I am using Hpple parser for iOS. Here is what I have and am trying but can't quite get it to work.

- (void)getData:(NSData*)factData {
    TFHpple *Parser = [TFHpple hppleWithHTMLData:factData];
    NSString *XpathQueryString = @"//day[@name='monday']/meal[@name='BREAKFAST']/counter[@name='Bread']/dish/name/info[@name='Plain Bagel']";
    NSArray *Nodes = [Parser searchWithXPathQuery:XpathQueryString];
    NSInteger count = Nodes.count;
    NSLog(@"count: %ld", count);
    for (TFHppleElement *element in Nodes) {
        NSLog(@"count inside: %ld", element.children.count);
    }
}

And the first count give 1. Which is right but count inside gives 7, which is where I get confused. And not sure why this happens. After I get inside the info tag I want to loop through for each tag, serving, calories, and calories from fat and get each tags text. But Im not sure why it gives 7?

Thanks for the help in advance.


Source: (StackOverflow)

Objective C Hpple to get commented element information

I'm starting my iPhone programming adventure, with a simple HTML scraping. I'm using the Hpple library to do the job, and I have a question... Suppose I have the following html to parse...

<div>
    <div> A <!-- Comment 1 --></div>
    <div> B </div>
    <div> C <!-- Comment 2 --></div>
</div>

How can I retrieve the commented parts? They don't show up on the objects... I was checking the docs but there's nothing pointing to that direction.. (also googling "hpple comment" doesn't produce the best results...).

thanks in advance.


Source: (StackOverflow)

hpple xpath problems

I am using hpple to parse an HTML document. I followed Ray Wenderlich’s tutorial and have everything working fine for their example file. However, I need to change it up a bit to read a certain HTML file for my friends blog. The file is more complex than the example I have used so far. The relevant part of the file (full uploaded on gist is:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<!-- snip -->
<div id="content" class="hfeed">
            <div class="post-21443 post type-post status-publish format-standard hentry category-about-catherine">

      <div class="postdate">
      Apr          <br />
      6            <br />
      2013         
      </div>
    <h2 class="entry-title"><a rel='nofollow' href="http://catherinepooler.com/2013/04/stampnation-live-retreat-updates/" title="StampNation LIVE Retreat Updates" rel="bookmark">StampNation LIVE Retreat Updates</a></h2>

    <div class="post-info"></div>       <div class="entry-content">
        <p><a rel='nofollow' href="http://catherinepooler.com/wp-content/uploads/2013/04/IMG_0560.jpg" ><img class="aligncenter size-large wp-image-21444" alt="StampNation LIVE" src="http://catherinepooler.com/wp-content/uploads/2013/04/IMG_0560-450x337.jpg" width="450" height="337" /></a></p> <p>StampNation LIVE is in full swing!  We are having a wonderful time.  I am taking a quick break from stamping and chatting to share a few photos with you.</p> <p>I think my favorite thing in getting ready for the retreat was setting up the Accessory Bar.  Each attendee received a small galvanized bucket with their fully glittered initial on it to fill up at the bar.  Awesome!</p>
<!-- snip -->

There are several of these sections within the file and I need to place all the

<h2 class = "entry-title"> 

(title="StampNation LIVE Retreat Updates") in an array. I have successfully placed the

<div class = "entry-content"> 

into an array by using the XPathQuery //div[@class = 'entry-content']/p. However, I can’t seem to get the title without the code crashing due to an empty array. Obviously my XPathQuery is incorrect. This is what I tried.

//h2[@class = 'entry-title']  (: this crashed :)

//div[@class = 'post-21443.....']//h2[@class = 'entry-title']  (: this crashed too.   ")

Along with a slew of other attempts!

Does anyone have any advice for me? I looked into many SO answers, and the examples that came with hpple, but I can not piece it together.

UPDATE: With Jens help I have changed the query to
NSString *postsXpathQueryString = @"//h2[@class = 'entry-title']/a";

This gets me an array, but I get this error as well now.

2013-04-08 10:26:30.604 HTML[12408:11303] * Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSArrayM objectAtIndex:]: index 4 beyond bounds [0 .. 3]' * First throw call stack: (0x210a012 0x1203e7e 0x20ac0b4 0x3852 0x2028fb 0x2029cf 0x1eb1bb 0x1fbb4b 0x1982dd 0x12176b0 0x2706fc0 0x26fb33c 0x2706eaf 0x2372bd 0x17fb56 0x17e66f 0x17e589 0x17d7e4 0x17d61e 0x17e3d9 0x1812d2 0x22b99c 0x178574 0x17876f 0x178905 0x9733ab6 0x181917 0x14596c 0x14694b 0x157cb5 0x158beb 0x14a698 0x2065df9 0x2065ad0 0x207fbf5 0x207f962 0x20b0bb6 0x20aff44 0x20afe1b 0x14617a 0x147ffc 0x1d2d 0x1c55) libc++abi.dylib: terminate called throwing an exception

UPDATE 2

Fixed the error index beyond bounds by putting in an if statement when I reloadData. I get an array in my NSLog, but it is not putting it in my table view. Table view comes up empty!! But no more crash!!!

FINAL UPDATE

It is now working, Jens helped me get the query correct and then I just had to fill in the table view. I had set the array count to 20 because Ray's tut had a zillion entries. My friends blog, only had four! Thanks for all the help.


Source: (StackOverflow)

Objective-C HTML parsing. Get all text between tags

I am using hpple to try and grab a torrent description from ThePirateBay. Currently, I'm using this code:

NSString *path = @"//div[@id='content']/div[@id='main-content']/div/div[@id='detailsouterframe']/div[@id='detailsframe']/div[@id='details']/div[@class='nfo']/pre/node()";
NSArray *nodes = [parser searchWithXPathQuery:path];
for (TFHppleElement * element in nodes) {
    NSString *postid = [element content];
    if (postid) {
        [texts appendString:postid];
    }
}

This returns just the plain text, and not any of the URL's for screenshots. Is there anyway to get all links and other tags, not just plain text? The piratebay is fomratted like so:

<pre>
    <a rel='nofollow' href="http://img689.imageshack.us/img689/8292/itskindofafunnystory201.jpg" rel="nofollow">
    http://img689.imageshack.us/img689/8292/itskindofafunnystory201.jpg</a>
More texts about the file
</pre>

Source: (StackOverflow)

Get text from HTML with hpple

the part that i am having trouble with reading is this html code:

<div id="main">
<h1>Hvorfor flager busserne i dag?</h1>
<h2>Idag den 26. august flager busserne ikke</h2>

My code in xcode looks like this:

   NSString *tutorialsXpathQueryString1 = @"/html/body/div [@id='main']";
    NSArray *tutorialsNodes1 = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString1];

    for (TFHppleElement * element in tutorialsNodes1) {
        NSLog(@"Link is: %@", [element objectForKey:@"h2"]);
        }

The code are running, but i can't get the text.. I am using Hpple as parser.

I really need some help, so everything is appriciated :-)


Source: (StackOverflow)

hpple html parse iphone sdk help?

I want to parse html.. so I have found some sample code over: http://blog.objectgraph.com/index.php/2010/02/24/parsing-html-iphone-development/ it uses hpple to parse html... but there is one problem this application is constantly crashing for some reason most probably it is this line over here:

NSURL *url = [NSURL URLWithString: @"http://www.objectgraph.com/contact.html"];
NSString *contents = [NSString stringWithContentsOfURL:url];
NSData *htmlData = [contents dataUsingEncoding:NSUTF8StringEncoding];

xCode gives me warning stringWithCOntentsofVariable is deprecated..

so could anyone help me solve this problem....by showing what code should I change?

thanks


Source: (StackOverflow)