我正在尝试解析登录iOS应用程序后的网站。解析HTML标签与hpple一起工作正常但我在POST方法之后检索HTTP代码时遇到了问题。
首先我这样做:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
NSDictionary *parameters = @{@"user": @"username",@"password": @"password"};
[manager POST:@"http://web" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
ResponseData = responseObject;
NSLog(@"Response: %@", ResponseData);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
然后我检索responseObject,我想这是我的HTML代码。
之后我用这段代码解析HTML代码:
NSString* stringwithdata = [NSString stringWithUTF8String:ResponseData.bytes];
NSData *tutorialsHtmlData = [NSData dataWithContentsOfFile:stringwithdata];
TFHpple *tutorialsParser = [TFHpple hppleWithHTMLData:tutorialsHtmlData];
NSString *tutorialsXpathQueryString = @"/html/head/title";
NSArray *tutorialsNodes = [tutorialsParser searchWithXPathQuery:tutorialsXpathQueryString];
NSMutableArray *newTutorials = [[NSMutableArray alloc] initWithCapacity:0];
Tutorial *tutorial = [[Tutorial alloc] init];
TFHppleElement *element = [tutorialsNodes objectAtIndex:0];
tutorial.title = [[element firstChild] content];
[newTutorials addObject:tutorial];
但编译器会返回这些内容:
2013-10-24 11:19:47.832 HtmlParsing[1565:70b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* +[NSString stringWithUTF8String:]: NULL cString'
我不知道如何访问返回POST的HTML数据。
Pd积。解析器代码不是问题,我已经尝试过直接加载网页而不用POST。