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.
Asked
Active
Viewed 134 times
1 Answers
-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
-
It is correct. you can google to see the swift version – Trong Vu Dec 30 '14 at 04:52