0
私は、プログラムでHTMLのフィールドの値を設定するソースコードの例を持っています。UIWebView - 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のような実際のWebページの代わりに、上に書いたようにのようなカスタムHTML内のフィールドの値を設定したいと思います。
「str」を実際のWebページのHTMLソースコードに置き換えて、「ElementbyId」を選ぶことができますか? [UIWebView loadRequest]
で
//---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];
を交換し、それはURLとのUIWebViewでWebビューがstringByEvaluatingJavaScriptFromString
仕事をするためにHTMLが含まれていますロードすることにより、
HTMLではなくURLからWebページを開くことをお探しですか? – Zakaria
URLからWebページを開き、stringByEvaulatingJavaScriptFromString関数を使用したいと考えています。 – at0m87