[英]UIWebView - how to extract the HTML code from webpages like Facebook?
我有一个源代码示例,该源代码以编程方式设置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以使stringByEvaluatingJavaScriptFromString
起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.