iOS 中使用JS提取网页数据,自动提交表单等
来源:互联网 发布:东莞seo外包公司 编辑:程序博客网 时间:2024/06/05 17:28
1.首先用一个webview加载网页
webView = [[UIWebView alloc] initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT)];
webView.delegate = self;
[self.view addSubview:webView];
NSURL *url =[[NSURL alloc] initWithString:@"http://www.reg007.com"];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webView loadRequest:request];
2.自动提交表单
NSString *ret = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('q')[0].value='18666666666';"];
NSLog(@"%@", ret);
ret = [webView stringByEvaluatingJavaScriptFromString:@"document.forms[0].submit(); "];
NSLog(@"%@", ret);
3.分析网页数据
NSString *count = [webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByTagName('li').length;"];
NSLog(@"%d %@", 0, count);
if (!count) {
return;
}
for (int i=0; i<[count intValue]; i++) {
NSString *classType = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementsByTagName('li')[%d].getAttribute(\"class\");", i]];
if ([classType isEqualToString:@"media"]) {
NSLog(@"%d %@\n", i+1, count);
NSString *name = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementsByTagName('li')[%d].childNodes[1].childNodes[0].childNodes[0].textContent;", i]];
NSString *href = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementsByTagName('li')[%d].childNodes[1].childNodes[0].childNodes[0].href;", i]];
NSString *desc = [webView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"document.getElementsByTagName('li')[%d].childNodes[1].childNodes[3].textContent;", i]];
NSLog(@"name: %@, href:%@, desc:%@\n\n", name, href, desc);
}
}
- iOS 中使用JS提取网页数据,自动提交表单等
- JS自动提交表单
- 编程实现网页表单数据的自动提交
- 编程实现网页表单数据的自动提交
- Delphi实现网页表单数据的自动提交
- Delphi实现网页表单数据的自动提交
- Delphi实现网页表单数据的自动提交
- Delphi实现网页表单数据的自动提交
- Delphi实现网页表单数据的自动提交
- Delphi实现网页表单数据的自动提交
- 关于使用js提交表单数据
- JS 自动提交表单跳转
- 使用JS提交表单
- 使用JS提交表单
- 手动提交表单的遍历提取数据
- C#实现网页表单自动提交
- 网页自动转发提交表单功能
- C#实现网页表单自动提交
- input number maxlength 失效 移动端使用
- android学习笔记6.07
- 第三方框架 开源项目
- thinkphp 常量的定义
- stringByReplacingOccurrencesOfString 去掉字符串,替换空格等等
- iOS 中使用JS提取网页数据,自动提交表单等
- 标准自定义控件CirvleView
- easyui之form表单提交
- js Date 获取 年 月 日 具体的值
- 完美解决ListView加载网络图片乱跳问题
- Espionage加密后分离磁盘.sparsebundle 文件打不开解决方案
- 如果回到从前,那又有何畏惧?
- Channel was inactive for too (>30000)long
- 概率论 - 求解概率题的基本思想