1.this is my code
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);
this is the out put
** 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 **
a easy test but the content(myTitle) always be null , i don't know why? help me.be greatly appreciated
I had a similar problem.
Try to replace this line:
with next:
or change your regular expression:
with
I hope that one of these ways will help you!