Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript UIWebView-如何从Facebook等网页中提取HTML代码?_Javascript_Html_Ios_Xcode_Uiwebview - Fatal编程技术网

Javascript UIWebView-如何从Facebook等网页中提取HTML代码?

Javascript UIWebView-如何从Facebook等网页中提取HTML代码?,javascript,html,ios,xcode,uiwebview,Javascript,Html,Ios,Xcode,Uiwebview,我有一个源代码示例,它通过编程设置HTML中字段的值 源代码部分如下所示: - (void)viewDidLoad { [super viewDidLoad]; myWebView.delegate = self; //---formulate the HTML string--- NSString *str = [[[NSString alloc] initWithString: @"<html>" " &

我有一个源代码示例,它通过编程设置HTML中字段的值

源代码部分如下所示:

- (void)viewDidLoad
{
[super viewDidLoad];

myWebView.delegate = self;

//---formulate the HTML string---
NSString *str = [[[NSString alloc] initWithString:
                @"<html>"
                 "    <body>"
                 "        <h1>The fields below are filled in programmatically</h1>"
                 "        <input id='username' value='UserName' />"
                 "        <input id='password' value='Password' type='password' />"
                 "    </body>"
                 "</html>"
                 ] autorelease];

//---load the UIWebView with the html string---
[myWebView loadHTMLString:str baseURL:nil];
}

//---wait for the UIWebView to finish loading---
- (void)webViewDidFinishLoad:(UIWebView *)webView {
//---access the 2 fields in the HTML---
[myWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('username').value='Wei-Meng Lee';"];
[myWebView stringByEvaluatingJavaScriptFromString:@"document.getElementById('password').value='TopSecret';"];
}
我想以编程方式设置像Facebook这样的网页中的字段值,而不是像上面写的那样自定义HTML

我应该如何将str替换为实际网页的html源代码,以便能够识别ElementbyId?

通过替换

//---formulate the HTML string---
NSString *str = [[[NSString alloc] initWithString:
            @"<html>"
             "    <body>"
             "        <h1>The fields below are filled in programmatically</h1>"
             "        <input id='username' value='UserName' />"
             "        <input id='password' value='Password' type='password' />"
             "    </body>"
             "</html>"
             ] autorelease];

//---load the UIWebView with the html string---
[myWebView loadHTMLString:str baseURL:nil];

使用[UIWebView loadRequest],它将加载带有URL的web视图,UIWebView将包含HTML以使StringByEvaluating JavaScriptFromString正常工作。

您正在寻找从URL而不是HTML打开网页?我想从URL打开网页,并能够使用StringByEvaluating JavaScriptFromString函数。