Any body can help me, I want to parse from a website, since I'm new in Objective C, I have no clue what should I do, is there any sample code that I can see to get some idea?
Asked
Active
Viewed 153 times
1
-
What you want to parse? Html/xml or binary data? Do you want to parse it on-fly from stream or you want to download it first? – Tutankhamen Aug 04 '12 at 15:38
-
I want to parse the links of videos and also parse the links of the news. then show the links of the videos in a table and show the links of the news in a different table. – Hamid Aug 04 '12 at 16:28
-
in this case you'd better use ASIHTTPRequest library... (see bellow). – Tutankhamen Aug 04 '12 at 17:02
-
@Tutankhamen Thank you. Unfortunately my question down voted and it causes to limit my access to ask a question, can you help me to fix this? – Hamid Aug 18 '12 at 04:37
2 Answers
1
try this one: http://allseeing-i.com/ASIHTTPRequest/
- (IBAction)grabURLInBackground:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://allseeing-i.com"];
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)requestFinished:(ASIHTTPRequest *)request
{
// Use when fetching text data
NSString *responseString = [request responseString];
// Use when fetching binary data
NSData *responseData = [request responseData];
}
- (void)requestFailed:(ASIHTTPRequest *)request
{
NSError *error = [request error];
}

Tutankhamen
- 3,532
- 1
- 30
- 38
-
ASI is good but no longer supported. Try MBRequest! https://github.com/mobiata/MBRequest – logancautrell Aug 05 '12 at 17:39
-
I don't know why my question down voted! I cannot ask a question anymore :( – Hamid Aug 18 '12 at 04:31
0
Your question is pretty unspecific, because the method is up to which kind of data you want to parse.
If you just want to fill a string with the contents of your website you could use:
NSString *foo = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.apple.com"] encoding:NSASCIIStringEncoding error:nil];
if you want to parse a xml or json file there are classes like the NSXMLParser.

ChoboDev
- 48
- 4
-
Never call that method from the main thread. It will block and likely kill your application. – logancautrell Aug 04 '12 at 15:27
-
The website that I want to parse has links of videos and links of news, I want to parse these links – Hamid Aug 04 '12 at 15:39
-
As @logancautrell said you will need a second thread for this operation. `[self performSelectorInBackground: @selector(readThread) withObject: [NSThread currentThread]];` As the next step you might read this Post [link](http://stackoverflow.com/questions/3020849/simple-libxml2-html-parsing-example-using-objective-c-xcode-and-htmlparser-h) for some information about html parsing in Xcode – ChoboDev Aug 04 '12 at 16:43
-
GCD is better :) prefer that over perform selector. http://developer.apple.com/library/ios/#documentation/Performance/Reference/GCD_libdispatch_Ref/Reference/reference.html – logancautrell Aug 05 '12 at 17:37
-
@logancautrell thanks a lot. My question got down voted and it causes to limit my access to ask a question, can anybody help me? – Hamid Aug 18 '12 at 04:33
-