熟悉 webkit 的人能否解释一下或指出正确的方向为什么以下代码不起作用
我想要做的是加载一个页面,让 webkit 解析它并简单地打印出标题。
这是我所拥有的:
#include <iostream>
#include <WebKit/WebKit.h>
using namespace std;
/*
Seek Help
*/
int main (int argc, char * const argv[]) {
NSAutoreleasePool *autoreleasepool = [[NSAutoreleasePool alloc] init];
WebFrame * mainFrame;
WebView * view = [[WebView alloc] initWithFrame: NSMakeRect (0,0,640,480)];
mainFrame = [view mainFrame];
NSString * url = @"http://test.com";
[[view mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
NSString * data = @"<html><head><title>testing</title></head><body>tester</body></html>";
[[view mainFrame] loadHTMLString:data baseURL: nil];
// NSString * urlString = [[NSString alloc] initWithUTF8String:"<html><head><title>Hello World</title></head><body><p>My first Web page.</p></body></html>"];
//[[view mainFrame] loadHTMLString:urlString baseURL:nil];
NSString * outerHtml = [(DOMHTMLElement *)[[[view mainFrame] DOMDocument] documentElement] innerHTML];
cout << "Html: " << [outerHtml UTF8String] << endl;
NSString * title = [view mainFrameTitle];
cout << "title: " << [title UTF8String] << endl;
[autoreleasepool release];
return 0;
}
输出为 html 且标题为空白
谢谢你的阅读