简体   繁体   中英

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.

The website is 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.
  3. Use UIWebView's stringByEvaluatingJavaScriptFromString to submit the form.
  4. Use UIWebView's stringByEvaluatingJavaScriptFromString to try and get the table's HTML but every time the table_container div returns empty.

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". 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:

  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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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