我是 iOS 开发新手,我正在尝试编写一个可以抓取网站(HTML)的应用程序。抓取谷歌只是一个例子 - 我正计划抓取一些更复杂的东西......
我的代码如下:
#import "KppleViewController.h"
#import "TFHpple.h"
@implementation KppleViewController
@synthesize theButton;
- (IBAction)buttonPressed:(UIButton *)sender {
NSLog(@"button Pressed");
NSURL *url = [NSURL URLWithString: @"http://www.google.com"];
NSData *htmlData = [NSData dataWithContentsOfURL: url];
TFHpple *xpathParse = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParse searchWithXPathQuery:@"//h3"];
TFHppleElement *element = [elements objectAtIndex:0];
NSString *h3Tag = [element content];
NSLog(@"x",h3Tag);
}
问题是,当我尝试写入控制台(通过
NSLog
)以查看是否有任何工作时,我收到错误。我收到的错误是“格式字符串未使用数据参数”
我在网上查遍了,没有结果。如果我注释掉 NSLog 以查看之前的代码是否正确,则会收到有关声明但未使用的 NSlog (h3Tag) 上方变量的错误。
任何帮助将不胜感激...
我也愿意接受任何其他抓取 HTML 的方法...
使用
NSLog(@"%@", h3Tag);
或
NSLog(h3Tag);
NSLog(@"x = %@",h3Tag);
Above line prints the value of h3Tag.
For more help about NSLog refer link: [http://www.cocoadev.com/index.pl?NSLog]