我正在尝试从此 html 数据中检索图像:
<div class="image">
<a href="http://www.website.com/en/105/News/10217/">
<img src="/images/cache/105x110/crop/images%7Ccms-image-000005554.gif"
width="105" height="110" alt="kollsge (photo: author)" />
</a>
</div>
这是我的代码:
HTMLNode *bodyNode = [parser body];
NSArray *imageNodes = [bodyNode findChildTags:@"div"];
for (HTMLNode *imageNode in imageNodes) {
if ([[imageNode getAttributeNamed:@"class"] isEqualToString:@"image"]) {
NSLog(@"%@", [imageNode getAttributeNamed:@"img src"]);
}
}
帮助将不胜感激。
我通过以下代码解决了它:
for (HTMLNode *imageNode in imageNodes) {
if ([[imageNode getAttributeNamed:@"class"] isEqualToString:@"image"]) {
HTMLNode *aNode = [imageNode firstChild];
HTMLNode *imgNode = [aNode nextSibling];
HTMLNode *imNode = [imgNode firstChild];
NSLog(@"%@", [imNode getAttributeNamed:@"src"]);
}
}