Home > OS >  scrape Highcharts series.data categories?
scrape Highcharts series.data categories?

Time:08-10

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.

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

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.

How can I get that data[n].category values for all n data points?

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.

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.

CodePudding user response:

You can adapt the python/selenium script here.

Most of the stuff remains as is, except for obvious changes (change the url, etc).

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])

EDIT: as pointed out in a comment, you can get the category data without a for loop using:

categories = driver.execute_script('return Highcharts.charts[0].userOptions.xAxis[0].categories')
  • Related