第一次来这里。
我正在尝试构建一个 Iphone 应用程序,该应用程序使用 hpple 从网站上的 HTML 表中提取单个字符串,该网站的示例在这里:http ://tsy.acislive.com/pip/stop_simulator_title.asp?naptan=37020349&pscode= 22&dest=&偏移量=1
和网站的代码:
<body class="ss_title">
<table class=piptitle cellpadding='0' cellspacing='0' width="100%"><tr><td align="center" valign="middle">Tannery Street - 02:32 (+1h)</td></tr></table>
</body>
我在我的应用程序中尝试了以下方法来获取文本“Tannery Street - 02:32 (+1h):
-(void)loadTitleTable{
NSLog(@"Load Title Method Called Successfully");
NSData *htmlData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://tsy.acislive.com/pip/stop_simulator_title.asp?naptan=37020349&pscode=22&dest=&offset=1"]];
TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements = [xpathParser searchWithXPathQuery:@"//tr/td"];
TFHppleElement *element = [elements objectAtIndex:0];
NSString *myTitle = [[element firstChild] content];
NSLog(myTitle);
_stopNOlabel.text = myTitle;
NSLog(@"Array: %@", elements);
}
我尝试使用 NSLog 输出数组,这是数组输出的内容:
数组: ( "{\n nodeAttributeArray = (\n {\n attributeName = align;\n nodeContent = center;\n },\n {\n attributeName = valign;\n nodeContent = middle;\n }\n ) ;\n nodeName = td;\n raw = \"\";\n}" )
我希望这里有人能够帮助我解决这个问题并将标签设置为文本字符串。
谢谢。达米安