我将如何使用 hpple Objective-C 包装器下的 xPath 来从该表中提取元素。理想情况下,我想将地址和价格放入数组或字典中。
我一直在尝试使用 hpple 目标 c 包装器将数据从位于此处的表中提取出来:http ://www.gaspry.com/index.php?zipcode=02169&action=search但没有成功获得正确的xpath 查询以提取信息。理想情况下,我想将此信息存储在一组数组中,一个用于地址,一个用于每个价格。我被困在如何从表中检索所有信息并且不确定我的 xPath 是否正确
到目前为止,我的代码是:
- (void)viewDidLoad {
[super viewDidLoad];
//Url Information
NSString *urlAddress = @"http://www.gaspry.com/index.php?zipcode=02169&action=search";
NSURL *url = [NSURL URLWithString:urlAddress];
NSData *htmlData = [[NSData alloc] initWithContentsOfURL:url];
//Start Parsing
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser search:@"//tBody[tr]"]; // get the table information
TFHppleElement *element = [elements objectAtIndex:0];
NSString *bodyTag = [element content];
NSLog(@"%@", bodyTag);
[xpathParser release];
[htmlData release];
}