我正在使用hpple解析HTML。所以现在我希望在用户触摸下一个按钮时更新我的文本。我的代码看起来像这样
NSURL *ur = [NSURL URLWithString:[NSString stringWithFormat:@"%@",url.text]];
NSData *htmlData = [NSData dataWithContentsOfURL: ur];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser search:@"//table[1]/tr[2]/td[2]/a/text()"]; // get the page title
TFHppleElement *element = [elements objectAtIndex:0];
NSString *h3Tag = [element content];
mi.text = h3Tag;
NSLog(@"%@",h3Tag);
[xpathParser release];
所以我是一个新的iPhone应用程序开发和相当新的编程。所以在这里我认为NSData需要更新。当用户触摸下一个按钮时,网址也会发生变化。所以对此有任何帮助将不胜感激
感谢
Tushar
答案 0 :(得分:0)
NSMutableString *tempString = [[NSMutableString alloc] initWithFormat:@"%@",url.text];
NSURL *ur =[[NSURL alloc] initWithString:tempString];
[tempString release];
NSData *htmlData = [[NSData alloc]initWithContentsOfURL:ur];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
[ur release];
[htmlData release];
NSArray *elements = [xpathParser search:@"//table[1]/tr[2]/td[2]/a/text()"]; // get the page title
TFHppleElement *element = [elements objectAtIndex:0];
NSString *h3Tag = [element content];
mi.text = h3Tag;
NSLog(@"%@",h3Tag);
[xpathParser release];
试试这段代码。
感谢。