I am trying to create an NHL betting system and need to web scrape live data every day. The table i need to web scrape is not available using the IMPORTHTML() function. I am trying to use python but have found no good tutorials for a beginner. I need help
>>> from bs4 import BeautifulSoup
>>> import requests
>>> from selenium import webdriver
>>> import pandas as ps
>>> PATH = "C:/webdrivers/chromedriver.exe"
>>> table_name = "table_container"
>>> csv_name = 'nhl_season_stats.csv'
>>> URL = "https://www.hockey-reference.com/leagues/NHL_2021.html"
>>> def get_nhl_stats(URL):
... driver = webdriver.Chrome(PATH)
... driver.get(URL)
... soup = BeautifulSoup(driver.page_source,'html')
... driver.quit()
... tables = soup.find_all('table',{"id":[table_name]})
... for table in tables:
... tab_name = table['id']
... tab_data = [[cell.text for cell in row.find_all(["th","td"])]
... for row in table.find_all("tr")]
... df = pd.DataFrame(tab_data)
... df.columns = df.iloc[0,:]
... df.drop(index=0,inplace= True)
... df.to_csv(csv_name, index = False)
... print(tab_name)
... print(df)
...
>>> get_nhl_stats(URL)
I keep getting this error:
DevTools listening on ws://127.0.0.1:59353/devtools/browser/2ad39b85-94a0-
4f64-a738-994c69f7373c
[10572:2256:0123/020420.281:ERROR:device_event_log_impl.cc(211)]
[02:04:20.281] USB: usb_device_handle_win.cc:1049 Failed to read descriptor
from node connection: A device attached to the system is not functioning.
(0x1F)
[10572:2256:0123/020420.283:ERROR:device_event_log_impl.cc(211)]
[02:04:20.283] USB: usb_device_handle_win.cc:1049 Failed to read descriptor
from node connection: A device attached to the system is not functioning.
(0x1F)