我正试图从这个互动图表中获取数据,该图表位于网站底部,如下所示:https://www.vgchartz.com/tools/hw_date.php?reg=USA&ending=Yearly
我在chrome中使用过开发者工具,但在"元素"选项卡中找不到数据点.
如果有人能看一下并告诉我数据点是否存储在页面上的某个地方,或者有什么方法可以使用Python,我将不胜感激
非常感谢你!
我正试图从这个互动图表中获取数据,该图表位于网站底部,如下所示:https://www.vgchartz.com/tools/hw_date.php?reg=USA&ending=Yearly
我在chrome中使用过开发者工具,但在"元素"选项卡中找不到数据点.
如果有人能看一下并告诉我数据点是否存储在页面上的某个地方,或者有什么方法可以使用Python,我将不胜感激
非常感谢你!
数据包含在该页面的<script>
标签中.要解析它,可以使用js2py
个库.例如:
import ast
import js2py
import requests
url = "https://www.vgchartz.com/tools/hw_date.php?reg=USA&ending=Yearly"
data = re.search(
r"StockChart\(({.*?})\);", requests.get(url).text, flags=re.S
).group(1)
data = js2py.eval_js("data = " + data + ";")
data = ast.literal_eval(str(data))
print(data)
打印:
{
"chart": {
"endOnTick": False,
"marginBottom": 90,
"marginLeft": 80,
"marginRight": 20,
"renderTo": "chart_container",
"startOnTick": False,
"zoomType": "y",
},
"legend": {"enabled": True},
"plotOptions": {"series": {"dataGrouping": {"smoothed": True}}},
"rangeSelector": {"selected": 5},
"series": [
{
"cropThreshold": 1,
"data": [
{"x": 1072933200000, "y": 1302609},
{"x": 1104555600000, "y": 2604003},
{"x": 1136091600000, "y": 5074726},
{"x": 1167627600000, "y": 8757992},
{"x": 1199163600000, "y": 10156740},
{"x": 1230786000000, "y": 10369446},
{"x": 1262322000000, "y": 8434877},
{"x": 1293858000000, "y": 4335275},
{"x": 1325394000000, "y": 2164269},
{"x": 1357016400000, "y": 600849},
],
...