我需要向网站发送 POST 请求以加载更多页面结果(我要解析大约 200 个结果(使用 TFHpple),但页面仅显示 40 个,您需要单击“显示更多结果”按钮加载更多)。
我试图在网上搜索如何发送 POST 请求,但我尝试过但没有成功:(谁能帮我弄清楚吗?
一般信息:
Remote Address:212.117.156.55:80
Request URL:http://www.d.co.il/DOTNET/ajax/GetMoreResults
Request Method:POST
Status Code:200 OK
File Name: GetMoreResults
如果需要任何其他信息,只需写信,我会给你。
非常感谢!
我这样做对吗?
NSURL *url=[NSURL URLWithString:@"http://www.d.co.il/SearchResults/?query=%D7%A9%D7%95%D7%A4%D7%A8%D7%A1%D7%9C&type=tag&location="];
NSData *data=[NSData dataWithContentsOfURL:url];
TFHpple *parser=[TFHpple hppleWithHTMLData:data];
NSString *XpathQueryString=@"//p[contains(@class, \"result-contact-address\")]";
NSArray *Nodes=[parser searchWithXPathQuery:XpathQueryString];
NSError *error;
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:nil];
NSURL *postUrl = [NSURL URLWithString:@"http://www.d.co.il/DOTNET/ajax/GetMoreResults"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:postUrl
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:60.0];
[request addValue:@"GetMoreResults" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"GetMoreResults" forHTTPHeaderField:@"Accept"];
[request setHTTPMethod:@"POST"];
NSDictionary *mapData = [[NSDictionary alloc] initWithObjectsAndKeys: @"1", @"batchNumber",
@"IOS TYPE", @"typemap",
nil];
NSData *postData = [NSJSONSerialization dataWithJSONObject:mapData options:0 error:&error];
[request setHTTPBody:postData];
NSURLSessionDataTask *postDataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
}];
[postDataTask resume];
int i=1;
for (TFHppleElement *element in Nodes) {
NSString *address = element.text;
NSLog(@"%@,%d",address,i);
i++;
}