从JavaScript图表中获取数据

时间:2017-05-15 08:57:08

标签: javascript web-scraping amcharts

在这个link上你会看到Apple iPhone的价格历史图表,我的目标是能够以某种方式访问​​这些数据,我查看了源代码并且没有提及任何价格,但在网络上有能力将鼠标悬停在数据点上并获得给定日期的价格,这意味着这些数据必须可用。

有什么想法吗?

2 个答案:

答案 0 :(得分:0)

如果您检查代码并使用图表稍微玩一下,您会看到:



<path cs="100,100" d="M-23.5,203.5 L-9.5,203.5 L-16.5,203.5 L-7.5,203.5 L-7.5,190.5 L6.5,190.5 L-0.5,190.5 L8.5,190.5 L8.5,148.5 L22.5,148.5 L15.5,148.5 L23.5,148.5 L23.5,162.5 L37.5,162.5 L30.5,162.5 L39.5,162.5 L39.5,176.5 L53.5,176.5 L46.5,176.5 L55.5,176.5 L55.5,162.5 L69.5,162.5 L62.5,162.5 L70.5,162.5 L70.5,176.5 L84.5,176.5 L77.5,176.5 L86.5,176.5 L86.5,148.5 L100.5,148.5 L93.5,148.5 L101.5,148.5 L101.5,162.5 L115.5,162.5 L108.5,162.5 L117.5,162.5 L117.5,176.5 L131.5,176.5 L124.5,176.5 L133.5,176.5 L133.5,176.5 L147.5,176.5 L140.5,176.5 L148.5,176.5 L148.5,148.5 L162.5,148.5 L155.5,148.5 L164.5,148.5 L164.5,162.5 L178.5,162.5 L171.5,162.5 L180.5,162.5 L180.5,162.5 L194.5,162.5 L187.5,162.5 L195.5,162.5 L195.5,176.5 L209.5,176.5 L202.5,176.5 L211.5,176.5 L211.5,176.5 L225.5,176.5 L218.5,176.5 L226.5,176.5 L226.5,176.5 L240.5,176.5 L233.5,176.5 L242.5,176.5 L242.5,148.5 L256.5,148.5 L249.5,148.5 L258.5,148.5 L258.5,103.5 L272.5,103.5 L265.5,103.5 L273.5,103.5 L273.5,54.5 L287.5,54.5 L280.5,54.5 L289.5,54.5 L289.5,71.5 L303.5,71.5 L296.5,71.5 L305.5,71.5 L305.5,71.5 L319.5,71.5 L312.5,71.5 L320.5,71.5 L320.5,87.5 L334.5,87.5 L327.5,87.5 L336.5,87.5 L336.5,87.5 L350.5,87.5 L343.5,87.5 L352.5,87.5 L352.5,19.5 L366.5,19.5 L359.5,19.5 L367.5,19.5 L367.5,19.5 L381.5,19.5 L374.5,19.5 L367.5,19.5 L367.5,19.5 L381.5,19.5 M0,0 L0,0" fill="none" stroke-width="2" stroke-opacity="1" stroke="#FFD400"></path>
&#13;
&#13;
&#13;

其中#FFD400是图表的颜色。也许数据是&#34; d&#34;属性,但我不太了解格式。

我希望它会有所帮助。

答案 1 :(得分:0)

数据存储在图表实例'dataProvider数组中。由于他们的代码被缩小,您将不得不使用全局AmCharts.charts数组来获取他们的dataProvider数组。请注意,此页面上有三个图表(统计信息选项卡中的微小迷你图表也是AmCharts实例)。数组按照页面中的创建顺序填充,因此第一个是迷你图,其他两个分别是受欢迎程度和价格历史。

这是我从人气历史图表的dataProvider访问第一项的控制台输出:

> AmCharts.charts[1].dataProvider[0]
Object {time: Mon Sep 16 2013 18:00:00 GMT-0400 (Eastern Daylight Time), value: 561756}

或者,您也可以使用浏览器的Web开发人员控制台并过滤掉AJAX / XHR调用以查找原始数据。