gpt4 book ai didi

ios - 从网站静默获取网站标题

转载 作者:行者123 更新时间:2023-11-29 03:05:01 24 4
gpt4 key购买 nike

我有一个网站的链接,我想得到它的标题。我试着用这段代码来做

UIWebView* hiddenWebView;
NSString* urlString = @"http://www.youtube.com/watch?v=OyORxdjGtlk";
NSURL* url = [NSURL URLWithString:urlString];
NSURLRequest* request = [NSURLRequest requestWithURL:url];
[hiddenWebView loadRequest:request];

NSString* text = [hiddenWebView stringByEvaluatingJavaScriptFromString:@"document.title"];

但结果是:text = NULL;我只想获取视频的名称

最佳答案

UIWebView 委托(delegate)设置为您的 ViewController(例如通过在 Interface Builder 中按住 ctrl 键拖动),然后:

- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSURL *url = [webView.request mainDocumentURL];
NSString *str = [url absoluteString];
NSString *title = [webView stringByEvaluatingJavaScriptFromString:@"document.title"];
NSLog(@"%s: url=%@ str=%@ title=%@", __PRETTY_FUNCTION__, url, str, title);
}

关于ios - 从网站静默获取网站标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22875586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com