[英]UIWebView - how to extract the HTML code from webpages like Facebook?
i have an example of a source code which programatically sets the value of fields in an HTML. 我有一个源代码示例,该源代码以编程方式设置HTML中字段的值。
The part of the source code is as such: 源代码部分如下:
- (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';"];
}
I would like to programmatically set value of fields in an actually webpage like Facebook instead of a custom HTML like such written above. 我想以编程方式在像Facebook这样的实际网页中设置字段的值,而不是像上面这样编写的自定义HTML。
How should i replace the "str" to an actual webpage's html source code so that i can pick out the "ElementbyId"? 如何将“ str”替换为实际网页的html源代码,以便可以选择“ ElementbyId”?
by replacing 通过替换
//---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];
with [UIWebView loadRequest]
and it will load the web view with the URL and the UIWebView will contain the HTML to make stringByEvaluatingJavaScriptFromString
work. 与
[UIWebView loadRequest]
,它将使用URL加载Web视图,并且UIWebView将包含HTML以使stringByEvaluatingJavaScriptFromString
起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.