我正在为website开发移动应用程序(适用于iOS 5.0及以上版本),用户可以直接从其着陆页查看某些数据。用户可以通过选择特定选项(即位置和/或日期)来细化结果。他们不提供任何Web服务调用,也不允许我们访问他们的数据库。所以我唯一的收集数据的方法是直接从网站上'刮'这个网站。如何从iOS的JavaScript页面中抓取数据?
我的问题是,我不知道如何使用户可以通过手机的http请求进行的更改。例如下面的网站:
可以从网站拉,并保存为一个字符串,用下面的命令
NSString *html = [NSString stringWithContentsOfURL:urlrequest encoding:NSUTF8StringEncoding error:&err];
我能分开的相关数据:
// I decided to add the script function name in case anyone wanted to look for themselves
<script type="text/javascript" language="Javascript">
//<![CDATA[
function loadData(){
var winMsgTitle = "Date: 04/11/2012";
// this is the actual data I'm concerned with:
gLatLong = new GLatLng(31.59019444444444, -110.50655555555555);
tmpMapIcon = new MapIcon("0_0", 21, 15);
marker = createMarker(gLatLong, 0.0, createInfoWinMsg(winMsgTitle, ".00", ".84", "5711", "2012", "", "07:00"), tmpMapIcon);
map.addOverlay(marker);
point = null;marker = null;
gLatLong = new GLatLng(32.2938260182, -110.7896411419);
tmpMapIcon = new MapIcon("0_0", 21, 15);
marker = createMarker(gLatLong, 0.0, createInfoWinMsg(winMsgTitle, ".00", "1.00", "1254", "2012", "", "07:00"), tmpMapIcon);
map.addOverlay(marker);
point = null;marker = null;
gLatLong = new GLatLng(33.5966853633, -112.1744066477);
tmpMapIcon = new MapIcon("0_0", 21, 15);
marker = createMarker(gLatLong, 0.0, createInfoWinMsg(winMsgTitle, ".00", ".70", "256", "2012", "", "07:00"), tmpMapIcon);
map.addOverlay(marker);
point = null;marker = null;
注:显然有更多的点,这只是剪断它
为了获得另一个位置或日期,我必须通过网站手动选择并选择右侧窗格中的选项。我的问题是,我如何通过objective-c以编程方式进行这些更改?
我能够发现该网站有一个“loadData”函数,我可以从mozilla的web控制台调用,该控制台包含我需要的全部内容。是否有可能只是调用该函数? – KronoS 2012-04-13 05:12:29
我想这可能会起作用。为什么不直接写和测试呢? – 2012-04-13 06:10:48
我并不确定如何大声笑。 – KronoS 2012-04-13 06:32:39