월간 저널을 표시하는 앱을 제작하고 있습니다. 저널에는 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” by Ira North</a></p>\n<p style=","
?
HTML 스크래핑은 악몽이며 확실한 근원입니다. 계속 유지하기위한 지속적인 작업 – Till
@Till 위의 편집을 참조하십시오. – user717452