0

I am trying to obtain the values of this columns (Year, Mom Dy, Hr, Mn, Sec) from the following [website https://www.ngdc.noaa.gov/hazel/view/hazards/tsunami/event-data?maxYear=2022&minYear=2010&country=USA] but I am new using Beautiful soup and I cannot find the table tag in the inspection to obtain the information. This are the columns

I have tried using this code:

url = 'https://www.ngdc.noaa.gov/hazel/view/hazards/tsunami/event-data? 
maxYear=2022&minYear=2010&country=USA'
r = requests.get(url)
soup = BeautifulSoup(r.content, 'html.parser')
soup.find('class',attrs={'ReactVirtualized__Grid__innerScrollContainer'})

But nothing is returned.

1 Answers1

0

Data comes from an API you can call. You can optionally create a date index and sort on that as well after generating a DataFrame from the returned json.

import requests
import pandas as pd

df = pd.DataFrame(requests.get('https://www.ngdc.noaa.gov/hazel/hazard-service/api/v1/tsunamis/events?++maxYear=2022&minYear=2010&country=USA').json()['items'])
df['date'] = pd.to_datetime(df[['year', 'month', 'day']])
df.set_index('date', inplace=True)
df.sort_index(inplace=True)
df

You can read about the API options here:

https://www.ngdc.noaa.gov/hazel/view/swagger#/Tsunami%20Events#

There is also a search tool here:

https://www.ngdc.noaa.gov/hazel/view/hazards/tsunami/event-search

QHarr
  • 83,427
  • 12
  • 54
  • 101