2014-07-20 27 views
0

我试图从网站获取有关网站的信息(如标题和Windows中的Safari浏览器中所见)以及该网站的描述,而不使用WebKit框架Xcode并将其作为文本显示在屏幕上。我只想知道必须获得URL属于使用Cocoa的网站/页面的标题。有一个教程或一些东西。这将是一个大的帮助。获取有关网站的信息使用Xcode的网址

回答

0

您可以通过下载目标网址上的HTML内容并解析它,例如使用hpple

实施例(未测试):

NSURL *url = [NSURL URLWithString:@"http://..."]; 

//Only using this for simplicity of the example. 
//You should really use an asynchronous method instead (see `NSURLSession`). 
NSData *urlData = [NSData dataWithContentsOfURL:url]; 

//Parse HTML and search for title element 
TFHpple *hppleParser = [[TFHpple alloc] initWithHTMLData:data]; 
TFHppleElement *titleElement = [hppleParser search:@"//title"][0]; 

NSString titleString = titleElement.text;