Is it possible to read the contents of a web page into a string so i can parse out the data?

前端 未结 2 1026
长发绾君心
长发绾君心 2021-01-23 13:22

I\'d like to be able to get my iphone to load a URL( or really the file that the url points to) into a string. The reason I want to be able to do this is so that I can then pars

2条回答
  •  死守一世寂寞
    2021-01-23 14:02

    First get the URL

    NSURL *anUrl = [NSURL URLWithString:@"http://google.com"];
    

    Then turn it into a string

    NSError *error;
    NSString *htmlString = [NSString stringWithContentsOfURL:anUrl encoding:NSUTF8Encoding error:&error];
    

    UPDATE:

    There is documentation on getting the contents of an URL by using NSURLConnection from the ADC site

    From there you can get the string representation of the downloaded data using

    NSString *htmlString = [[NSString alloc] initWithData:urlData encoding:NSUTF8Encoding];
    

提交回复
热议问题