I want to convert a website table to pandas df, but BeautifulSoup
doesn't recognize the table (snipped image below). Below is the code I tried with no luck.
from bs4 import BeautifulSoup
import requests
import pandas as pd
url = 'https://www.ndbc.noaa.gov/ship_obs.php'
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
soup = BeautifulSoup(response.content, 'html.parser')
tables = soup.find_all('table', rules = 'all')
#tables =soup.find_all("table",{"style":"color:#333399;"}) #instead of above line to specify table with no luck!
df = pd.read_html(table, skiprows=2, flavor='bs4')
df.head()
I also tried the code below with no luck
df = pd.read_html('https://www.ndbc.noaa.gov/ship_obs.php')
print(df)