0

I'm trying to parse an HTML page with a lot of tables. I've searched the net on how to parse HTML with Objective C and I found hpple. I'd look for a tutorial which lead me to:

http://www.raywenderlich.com/14172/how-to-parse-html-on-ios

With this tutorial I tried to parse some forum news which has a lot of tables from this site (Hebrew): news forum

I tried to parse the news title, but I don't know what to write in my code. Every time I try to reach the path I get, "Nodes was nil."

The code of my latest attempt is:

 NSURL *contributorsUrl = [NSURL URLWithString:@"http://rotter.net/cgi-bin/listforum.pl"];
NSData *contributorsHtmlData = [NSData dataWithContentsOfURL:contributorsUrl];

// 2
TFHpple *contributorsParser = [TFHpple hppleWithHTMLData:contributorsHtmlData];

// 3
NSString *contributorsXpathQueryString = @"//body/div/center/center/table[@cellspacing=0]/tbody/tr/td/table[@cellspacing=1]/tbody/tr[@bgcolor='#FDFDFD']/td[@align='right']/font[@class='text15bn']/font[@face='Arial']/a/b";
NSArray *contributorsNodes = [contributorsParser searchWithXPathQuery:contributorsXpathQueryString];

// 4
NSMutableArray *newContributors = [[NSMutableArray alloc] initWithCapacity:0];
for (TFHppleElement *element in contributorsNodes) {
    // 5
    Contributor *contributor = [[Contributor alloc] init];
    [newContributors addObject:contributor];

    // 6

Could somebody guide me through to getting the titles?

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49

1 Answers1

0

Not sure if that's the option for you, but if desired table have unique id's you could use a messy approach: load that html into UIWebView and get contents via – stringByEvaluatingJavaScriptFromString: like this:

// desired table container's id is "msg"
NSString* value = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementById('msg').innerHTML"];
MANIAK_dobrii
  • 6,014
  • 3
  • 28
  • 55