通过调用document.write()创建的解析表

时间:2011-10-27 13:49:26

标签: html objective-c ios

我想解析一个网页,以获取该页面上的表格内容。但是,该表是通过调用document.write()和几个javascript函数创建的。即,当我加载该页面的URL请求时,我得到的源不包含该表的html标签。是否有可能获得最终页面的源(即包含我想要的表的html标签的源)?我非常好奇我可以在safari浏览器的开发者工具中查看“最终页面源”,但不能查看页面的来源。 这是页面the source

的来源

2 个答案:

答案 0 :(得分:0)

是的,只需使用web开发人员扩展程序或firebug扩展程序在firefox中使用view generated source

答案 1 :(得分:0)

您应该使用实现NSConnectionDataDelegate协议并使用NSConnection类。我相信,在调用-(void) connectionDidFinishLoading:(NSURLConnection *)connection时,页面已完全加载。

-(void) requestPage
{
    NSString *urlString = @"http://the.page.you.want.com";
    NSURL *url = [NSURL URLWithString:urlString];

    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLCacheStorageAllowed timeoutInterval:20.0f];


    responseData = [[NSMutableData alloc] init];
    connection = [[NSURLConnection connectionWithRequest:request delegate:self] retain];
    delegate = target;
}


-(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{   
    if ([response isKindOfClass:[NSHTTPURLResponse class]])
    {
        NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*) response; 
        //If you need the response, you can use it here
    }
}

-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    [responseData appendData:data];
}

-(void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
    [responseData release];
    [connection release];
}

-(void) connectionDidFinishLoading:(NSURLConnection *)connection
{
    if (connection == adCheckConnection)
    {
        NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];

        //You've got all the data now
        //Do something with your response string


        [responseString release];
    }

    [responseData release];
    [connection release];
}