1.这是我的代码
NSStringEncoding encoding2 = NSUTF8StringEncoding;
// i am from china
NSString *c1 = @"<html><head><title A='sss'>sss</title></head><body><a href='sssssss这个中文就么哟sa哈aa'>asas</a></body></html>";
htmlData = [c1 dataUsingEncoding:encoding2];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser searchWithXPathQuery:@"//a"];
TFHppleElement *element = [elements objectAtIndex:0];
NSString *myTitle = [element content];
NSLog(@"%@",element.tagName);
NSLog(@"%@",myTitle);
NSString *attr = [element objectForKey:@"href"];
NSLog(@"%@",attr);
这是输出
** 2012-08-12 14:59:34.624 HHXY[1506:f803] a 2012-08-12 14:59:34.625 HHXY[1506:f803] (null) 2012-08-12 14:59:34.625 HHXY[1506:f803] sssssss这个中文就么哟sa哈aa **
一个简单的测试,但 content(myTitle) 总是为 null ,我不知道为什么?帮助我。不胜感激