diff --git a/Code/HTMLDocument.h b/Code/HTMLDocument.h index 81f9201..294403a 100644 --- a/Code/HTMLDocument.h +++ b/Code/HTMLDocument.h @@ -54,6 +54,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (strong, nonatomic) HTMLElement * __nullable rootElement; +/** + The first child element of the root with the tag name `body`. Typically the `
` element. + */ +@property (readonly, nonatomic) HTMLElement * __nullable bodyElement; + @end NS_ASSUME_NONNULL_END diff --git a/Code/HTMLDocument.m b/Code/HTMLDocument.m index 6f4b957..f4b4d8d 100644 --- a/Code/HTMLDocument.m +++ b/Code/HTMLDocument.m @@ -85,6 +85,19 @@ - (void)setRootElement:(HTMLElement * __nullable)rootElement } } +- (HTMLElement * __nullable)bodyElement +{ + for (id child in self.rootElement.children) { + if ([child isKindOfClass:[HTMLElement class]]) { + HTMLElement *elem = child; + if ([elem.tagName isEqualToString:@"body"]) { + return elem; + } + } + } + return nil; +} + static id FirstNodeOfType(id