2012-11-23 1 views
0

월간 저널을 표시하는 앱을 제작하고 있습니다. 저널에는 XML이 없으며 매월 PDF의 제목 헤더와 URL 만 변경하면됩니다. 이것은 항상 소스 코드에서 같은 장소를 저장, 그래서특정 Div 클래스 내 첫 번째 URL 추출

DIV 클래스 = 엔트리 clearfix 포스트/DIV

태그 내의 모든 텍스트를 찾는 다음 첫 번째 URL을 추출에서 찾고 . 이전에는 XML을 파싱했지만 XML은 사용하지 않았습니다. 이것에 대한 최선의 선택은 무엇입니까?

UPDATE :

만 소스 코드의 한 지점에서 페이지가 To Download the PDF, click here을 말하는가. 그래서 다음 스캐너를 설정했습니다 :

NSURL *url = [NSURL URLWithString:@"http://www.thejenkinsinstitute.com/Journal/"]; 
NSString *content = [NSString stringWithContentsOfURL:url]; 
NSString * aString = content; 
NSMutableArray *substrings = [NSMutableArray new]; 
NSScanner *scanner = [NSScanner scannerWithString:aString]; 
[scanner scanUpToString:@"<p>To Download the PDF, <a href=\"http://michaelwhitworth.com/wp-content/HE22.pdf\">" intoString:nil]; // Scan all characters before # 
while(![scanner isAtEnd]) { 
    NSString *substring = nil; 
    [scanner scanString:@"<p>To Download the PDF, <a href=\"" intoString:nil]; // Scan the # character 
    if([scanner scanUpToString:@"\"" intoString:&substring]) { 
     // If the space immediately followed the #, this will be skipped 
     [substrings addObject:substring]; 
    } 
    [scanner scanUpToString:@"#" intoString:nil]; // Scan all characters before next # 
} 
NSLog(@"Here is the Substring%@", substrings); 
// do something with substrings 
[substrings release]; 

콘솔에서 반환되는 첫 번째 것은 PDF의 URL입니다. 그러나 훨씬 더 많은 내용이 포함되어 있습니다. 다음은 간단한 발췌 부분입니다. 나는 나에게 단지 URL, 아무것도 더주는에서이 계속 잘못하고있는 무슨

"2012-11-23 15:33:36.383 Jenkins[8306:c07] Here is the Substring( "http://michaelwhitworth.com/wp-content/HE22.pdf", "#8220;As the Bible School Goes So Goes the Congregation&#8221; by Ira North</a></p>\n<p style=","

?

+0

HTML 스크래핑은 악몽이며 확실한 근원입니다. 계속 유지하기위한 지속적인 작업 – Till

+0

@Till 위의 편집을 참조하십시오. – user717452

답변

0

나는 비슷한 것을했는데, 작은 웹 서비스 (API는 기본적으로 필요한 HTML을 폐기하는 간단한 Ruby 응용 프로그램이었고, REST 방식으로 반환했다.) 웹 서비스/API는 훌륭했다. 아이디어가 HTML에서 변경되면 (id의 요소 변경과 같이) 파싱중인 노드의 경로를 변경하기 위해 iOS 앱을 업데이트 할 필요가 없기 때문에 아이디어가 필요합니다.

관련 문제