获取有关网站的信息使用Xcode的网址

问题描述:

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

试试这个:

- (void)webViewDidFinishLoad:(UIWebView *)webView 
{ 
    NSString* title = [webView stringByEvaluatingJavaScriptFromString: @"document.title"]; 
    navbar.title = title; 
} 

来自http://blog.mcohen.me/2008/12/12/getting-the-title-of-a-web-view-in-cocoa-touch/

如果你不想显示web视图,使其隐蔽性和使用上面的委托方法来获得你想要的...

您可以通过下载目标网址上的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;