Xpath用法

第三方:TFHpple

#import "TFHpple.h"
    TFHpple *hpple = [TFHpple hppleWithHTMLData:data encoding:@"utf-8"];
    NSArray *eles = [hpple searchWithXPathQuery:@"//div[@class='article block untagged mb15']"];
    [eles enumerateObjectsUsingBlock:^(TFHppleElement *obj, NSUInteger idx, BOOL * _Nonnull stop) {
        
        NSArray *tempArr = [obj searchWithXPathQuery:@"//div[@class='content']//span"];
        TFHppleElement *e = tempArr.firstObject;
        NSString *content = e.content;
        
        NSArray *tempArr2 = [obj searchWithXPathQuery:@"//div[@class='author clearfix']/a[@href]/img[@src]"];
        TFHppleElement *e2 = tempArr2.firstObject;
        NSString *content2 = e2.attributes[@"src"];

        
        CellItem *item = [[CellItem alloc]initWithContentString:content andImageURL:content2];
        [_datas addObject:item];
    }];

你可能感兴趣的:(Xpath用法)