mac 整理html,MAC解析HTML

- (void)fetchOneHtmlwithUrl:(NSURL *)url withCode:(NSString *)code withValueIn:(double)valueIn withMoneyIn:(double)moneyIn

{

NSError *error;

NSData *dataGB2312 = [[NSData alloc] initWithContentsOfURL:url options:NSDataReadingMappedIfSafe error:&error];

NSStringEncoding gb2312Encoding =CFStringConvertEncodingToNSStringEncoding(kCFStringEncodingGB_18030_2000);

NSString *htmlGB2312 = [[NSString alloc] initWithData:dataGB2312 encoding:gb2312Encoding];

NSString *utf8HtmlStr = [htmlGB2312 stringByReplacingOccurrencesOfString:@"charset=gb2312"

withString:@"charset=utf-8"];

NSData *dataUTF8 = [utf8HtmlStr dataUsingEncoding:NSUTF8StringEncoding];

ParseResultBean *bean = [ParseResultBean alloc];

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:dataUTF8];

NSArray *eArrayCode = [xpathParser searchWithXPathQuery:@"/html/body/div[1]/div[7]/div[2]/div[1]/div[1]/div[1]/span[2]"];

TFHppleElement *eCode = [eArrayCode objectAtIndex:0];

bean->code = [[eCode attributes] objectForKey:@"title"];

[allRows addObject:bean];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值