-8

I need to have a variable that contains the text of a label. But the label is in a website in aspx. I try with NSURLSession but i don't understand which method is correct.

AlbertoS
  • 1
  • 3

1 Answers1

-2

This is simple way

1) Get the html content from the url: you can use - NSURLSession NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:nil delegateQueue:nil];

[[session dataTaskWithURL:[NSURL URLWithString:urlString]
        completionHandler:^(NSData *data,
                            NSURLResponse *response,
                            NSError *error) {

- NSURLConnection:

NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self];
  • dataWithContentsOfURL:

    NSData * htmlData = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];

2) Parse the variable content from that content using TFHpple

TFHpple *xpathParser = [[TFHpple alloc] initWithHTMLData:htmlData];
NSArray *elements  = [xpathParser search:@"//variable"]; // get the variable

Hope it help

Trong Vu
  • 91
  • 8