Converting svg from Highcharts data into data points

后端 未结 2 1716
执笔经年
执笔经年 2021-02-03 15:04

I am looking to scrape data from this site\'s mma data and parsing a few highcharts tables. I am clicking a link with selenium and then switching to the chart. I go to this s

2条回答
  •  情话喂你
    2021-02-03 15:49

    I could not figure out how to convert SVG data into what is displayed on the graph you mentioned, but wrote the following Selenium Python script:

    from selenium import webdriver
    import time
    
    driver = webdriver.Chrome()
    driver.get('https://www.bestfightodds.com/events/ufc-fight-night-108-swanson-vs-lobov-1258')
    actions = webdriver.ActionChains(driver)
    actions.move_to_element(driver.find_element_by_id('oID1013467091'))
    actions.click()
    actions.perform()
    time.sleep(3)
    driver.switch_to_active_element()
    chart_number = driver.find_element_by_id('chart-area').get_attribute('data-highcharts-chart')
    chart_data = driver.execute_script('return Highcharts.charts[' + chart_number + '].series[0].options.data')
    for point in chart_data:
        e = driver.execute_script('return oneDecToML('+ str(point.get('y')) + ')')
        print(point.get('x'), e)
    

    Here we are using Highcharts API and some js from the page sources, that converts server response for this chart to what we see on a graph.

提交回复
热议问题