0

I'm new to objective c and trying to parse HTML with TFHpple, and having trouble with Xpath.

Currently I'm trying to get news topic from main page of Yahoo Japan. but it return nil.

NSStringEncoding UTF = 4;
NSString *htmlWillInsert = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.yahoo.co.jp/"] encoding:UTF error:nil];
NSData *htmlData = [htmlWillInsert dataUsingEncoding:NSUnicodeStringEncoding];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser searchWithXPathQuery:@"/html/body/div/div[2]/div[3]/div/div/div[2]/div/div/ul/li/a"];   

NSLog(@"%@", elements);
for (TFHppleElement *element in elements)
{  
    NSLog(@"%@", [element content]);
}
[xpathParser release];   

i could get html from yahoo.com . but can't get anything from yahoo JP.

dose any1 know the solution?

Tetsu
  • 23
  • 2
  • 4
  • Add a log of the raw response. Maybe yahoo.jp is in html (in opposition to xhtml) so you can't parse it as xml! – Jaffa Oct 12 '11 at 06:21
  • thanks for a comment Geoffroy.My debug log says...2011-10-12 19:31:13.481 TFHpple _Test[20685:b303] Nodes was nil. 2011-10-12 19:31:13.483 TFHpple _Test[20685:b303] ( ) and i think yahoo Jp is xhtml.dosent make sense why it doesn't – Tetsu Oct 12 '11 at 10:45
  • -> Yahoo.jp, so it's not xhtml. – Jaffa Oct 12 '11 at 11:47
  • oops..sry about it Geoffroy.so...do you know any other way to parse html?or other component likes TFHpple? – Tetsu Oct 12 '11 at 14:08

1 Answers1

0

As yahoo.jp is in html and not xml, you can't parse it as such.

To parse HTML, you can see the examples given in this post : parsing HTML on the iPhone

Community
  • 1
  • 1
Jaffa
  • 12,442
  • 4
  • 49
  • 101