简体   繁体   English

刮 Highcharts series.data 类别?

[英]scrape Highcharts series.data categories?

I want to export chart data from a website .我想从网站导出图表数据。

Using console.log(Highcharts.charts[0].series[0].data) I can see the data I need.使用console.log(Highcharts.charts[0].series[0].data)我可以看到我需要的数据。

I want the values stored under Highcharts.charts[0].series[0].data[n].category for n in [0, 1, ..., N_data_points-1] (These values are the time-stamps of the data points in the plot.)我想要存储在Highcharts.charts[0].series[0].data[n].category for n in [0, 1, ..., N_data_points-1]下的值(这些值是plot 中的数据点。)

When I try to use JSON.stringify(Highcharts.charts[0].series[0].data) to write the whole data attribute I get Uncaught TypeError: Converting circular structure to JSON .当我尝试使用JSON.stringify(Highcharts.charts[0].series[0].data)写入整个数据属性时,我得到Uncaught TypeError: Converting circular structure to JSON

How can I get that data[n].category values for all n data points?如何获取所有n数据点的data[n].category值?

Note that the x axis data can be obtained straightforwardly via Highcharts.charts[0].series[0].processedXData , but these are not the dates, just consecutive integers.请注意,x 轴数据可以通过Highcharts.charts[0].series[0].processedXData直接获得,但这些不是日期,只是连续整数。

Also, I don't necessarily need to do this via console.此外,我不一定需要通过控制台执行此操作。 If it's possible to get the data via, say, a Python script, that would do as well.如果可以通过 Python 脚本获取数据,那也可以。

You can adapt the python/selenium script here .您可以在此处调整 python/selenium 脚本。

Most of the stuff remains as is, except for obvious changes (change the url, etc).除了明显的变化(更改 url 等)外,大部分内容保持原样。

You can get the category data of each data point with:您可以通过以下方式获取每个数据点的类别数据:

dates = []

for i in range(len(values)):
    date = driver.execute_script('return Highcharts.charts[0].series[0].data[{}].category'.format(i))

    dates.append(date[0])

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

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