Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python, Web scraping data from an interactive chart

How can I retrieve this data in the graph from this site and then save it in a DataFrame using python?

https://umm.gassco.no/reductionFields

I have tried to retrieve the data with this code but do not know how to proceed

import requests 
s=requests.session() s1=s.get("https://umm.gassco.no/reductionFields") s2=s.get("https://umm.gassco.no/disclaimer/acceptDisclaimer?")
like image 369
FFV Avatar asked Jul 10 '26 06:07

FFV


1 Answers

To get the data from graph as Pandas DataFrame you can use next example:

import re
import requests
import pandas as pd

url = "https://umm.gassco.no/reductionFields"
redir_url = "https://umm.gassco.no/disclaimer/acceptDisclaimer?"

with requests.session() as s:
    s.get(url)
    html_doc = s.get(redir_url).text

df = pd.DataFrame(
    {"Time": a, "Value": b}
    for a, b in re.findall(r"d3\.push\(\[(.*?), (.*?)\]\)", html_doc)
)
df['Time'] = pd.to_datetime(df['Time'], unit='ms')
print(df.head())

Prints:

                 Time               Value
0 2023-04-18 10:00:00  -50.93000000000001
1 2023-04-19 10:00:00              -40.93
2 2023-04-20 10:00:00  -60.92999999999999
3 2023-04-21 10:00:00  -60.92999999999999
4 2023-04-22 10:00:00  -60.92999999999999
like image 116
Andrej Kesely Avatar answered Jul 11 '26 21:07

Andrej Kesely