2013-10-17 2 views
0

저는 iPhone 개발에 초보자입니다. HTML로 응답하는 URL이 있습니다. 내 요구 사항은 응답의 모든 단락 태그를 가져 오는 것입니다. 하지만 TFHpple 라이브러리를 사용하고 특정 xPath 데이터를 가져오고 있습니다. 하지만 응답 내 모든 <p> 태그 데이터가 필요합니다. 아무도 나를 도와주세요. 미리 감사드립니다 .. Objective-C-HMTL-Parser객관적인 c에서 HTML 응답을 구문 분석하는 방법

Hpple HTML을 구문 분석 libxml 주위

답변

0

객관적인 C 래퍼 : 좋은 목표 - C 래퍼를 HTML을 구문 분석에 대한 XPathQuery 라이브러리에. Hpple

위의 내용은 좋은 문서와 함께 html 구문 분석에 사용할 수있는 간단하고 편리한 라이브러리입니다.

그리고 http://www.raywenderlich.com/14172/how-to-parse-html-on-ios

그것이 도움이되기를 바랍니다이 링크에있는 튜토리얼

...

0

때로는 파라 태그는 범위를 가지고 있으며, 경우에 따라서는 그 아이들을 통해 반복에 의해 내가 처리하기 위해 노력하고 건의 할 것,하지 않기 때문에

NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]; 
NSData * data  = [NSData dataWithContentsOfFile:filePath]; 
TFHpple * tutorialsParser  = [[TFHpple alloc] initWithHTMLData:data]; 

NSString *tutorialsXpathQueryString = @"//div[@id='NewsPageSubTitle']"; 
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString]; 

for (TFHppleElement * element in tutorialsNodes) { 
    NSLog(@"%@", element); 
    NSLog(@"%@", [element tagName]); 
    NSLog(@"%@", [element attributes]); 
    NSLog(@"%@", [element children]); 
    for (TFHppleElement *childElement in [element children]) { 
      NSLog(@"%@", childElement); 
    } 
} 
관련 문제