0

我正在尝试解析登录到 iOS 应用程序后的网站。使用 hpple 解析 HTML 标签可以正常工作,但是在 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);
}];

然后我检索我认为是我的 HTML 代码的 responseObject。

之后,我使用以下代码解析该 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。

4

0 回答 0