UIWebView-如何从Facebook等网页中提取HTML代码
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将包含使stringByEvaluatingJavaScriptFromString
工作的HTML。
相关文章:
- 用于提取 HTML 标记子元素的正则表达式
- 如何使用mozilla插件sdk API从响应中提取html页面
- 从字符串中提取HTML标记并“使用”它
- 使用 jQuery 提取 HTML 标记之外的文本
- 从动态页面中提取 html 源代码
- 提取 html 页面的页眉和页脚
- 提取 html 元素之间的文本
- 用于提取 HTML 标记的 XPaPath
- 如何使用 jQuery 从使用 Ajax 获取的内容中提取 HTML
- 使用javascript提取HTML
- 提取html页面中所有以.js扩展名结尾的链接
- 从Javascript关联数组中提取HTML链接以应用于D3生成的表
- 使用PhantomJS提取html和文本
- 使用javascript/jquery从字符串中提取html元素
- 如何提取html并将其添加到数组中
- 如何从纯文本中提取html标记
- UIWebView-如何从Facebook等网页中提取HTML代码
- 如何使用javascript或jquery从字符串中提取html标记的内容
- 正确提取HTML
- regex来提取html注释属性