简体   繁体   English

使用Objective-C从HTML获取JavaScript生成的表

[英]Getting table generated by javascript from HTML with Objective-C

I am trying to develop an app that needs to get data from a table on a website, the problem is that I need to get the HTML of the table after the javascript function has run but I've had no success with it so far. 我正在尝试开发一个需要从网站上的表中获取数据的应用程序,问题是我需要在javascript函数运行后获取表的HTML,但到目前为止我还没有成功。

The website is www.mylocalcrime.com. 该网站是www.mylocalcrime.com。 What I currently have the application doing is, 我目前正在让应用程序执行的操作是

  1. Load the page in a web view. 在网页视图中加载页面。
  2. Use UIWebView's stringByEvaluatingJavaScriptFromString to fill the search field. 使用UIWebView的stringByEvaluatingJavaScriptFromString填充搜索字段。
  3. Use UIWebView's stringByEvaluatingJavaScriptFromString to submit the form. 使用UIWebView的stringByEvaluatingJavaScriptFromString提交表单。
  4. Use UIWebView's stringByEvaluatingJavaScriptFromString to try and get the table's HTML but every time the table_container div returns empty. 使用UIWebView的stringByEvaluatingJavaScriptFromString尝试获取表的HTML,但是每次table_container div返回空时。

Any ideas would be greatly appreciated. 任何想法将不胜感激。

Thanks 谢谢

Its really simple. 真的很简单。 Check out the page code, and you will find a javascript file called "my_local_crime.js". 检出页面代码,您将找到一个名为“ my_local_crime.js”的javascript文件。 This is the heart of the data you get from the site. 这是您从网站获得的数据的核心。 When you get to the code lines 164-169 in this document, you get the following javascript code: 当您到达本文档中的代码行164-169时,您将获得以下javascript代码:

  var url = "http://api.spotcrime.com/crimes.json?";
  url += "lat="+center.lat();
  url += "&lon="+center.lng();
  url += "&radius="+radius;
  url += "&callback=?";
  url += "&key=MLC-restricted-key";

This is how the javascript on the page generates the JSON query. 这是页面上的javascript生成JSON查询的方式。 You can do the same within objective-c, create the correct query, and get JSON data from api.spotcrime.com instead of going via mylocalcrime.com. 您可以在Objective-C中执行相同的操作,创建正确的查询,并从api.spotcrime.com获取JSON数据,而无需通过mylocalcrime.com。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM