rokala
rokala

Reputation: 1

ValueError: no tables found

Okay, should be an easy one for some of you, but I could not find any solution to this problem of mine. I'm trying to scrape a table from NHL.com, but it won't find any – I've tried 'table', 'ReactTable', anything.

import pandas as pd
import requests
import urllib.request
import time
from bs4 import BeautifulSoup
from pandas_profiling import ProfileReport
import numpy as np
import matplotlib as plt
url = "http://www.nhl.com/stats/teams?report=goalsbyperiod&reportType=game&dateFrom=2020-03-11&dateTo=2020-09-11&gameType=3&filter=gamesPlayed,gte,1&sort=period1GoalsFor&page=0&pageSize=50"
response = requests.get(url)
soup = BeautifulSoup(response.text, 'html.parser')
result = soup.find_all('table')
df_raw = pd.read_html(str(table))[0]

It only says ValueError: no tables found

The same code works in most of the websites I use. Please, help.

Upvotes: 0

Views: 2250

Answers (1)

Zaraki Kenpachi
Zaraki Kenpachi

Reputation: 5730

The data on page is inside div not table. You can use selenium for this:

from selenium import webdriver
import os
import time

chrome_driver = os.path.abspath(os.path.dirname(__file__)) + '/chromedriver'
browser = webdriver.Chrome(chrome_driver)
url = 'http://www.nhl.com/stats/teams?report=goalsbyperiod&reportType=game&dateFrom=2020-03-11&dateTo=2020-09-11&gameType=3&filter=gamesPlayed,gte,1&sort=period1GoalsFor&page=0&pageSize=50'

browser.get(url)

time.sleep(3)

data = browser.find_element_by_class_name('rt-tbody').text

Output:

1
Colorado Avalanche
15
9
5
--
--

Upvotes: 1

Related Questions