I need a solution for scaping tables. Currently getting a TimeoutException: Message:
driver = webdriver.Chrome('C:\Drivers\chromedriver.exe')
waitWD = WebDriverWait (driver, 10)
link = "https://fantasyteamadvice.com/dfs/mlb/ownership"
driver.get (link)
html=waitWD.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"table[data-testid='ownershipTablemlb']"))).get_attribute("outerHTML")
data = pd.read_html(html)[0]
data.to_csv("inputs/dk_ownership.csv")
driver.quit()
Try this:
import httpx
import pandas as pd
URL = "https://fantasyteamadvice.com/api/user/get-ownership"
json_data = {
"sport": "mlb",
}
response = httpx.post(URL, json=json_data)
ownership = response.json()["ownership"]
ownership = pd.DataFrame(ownership)
ownership.to_csv("ownership.csv")
Output (first few records):
,fullname,team,dkPrice,fdPrice,dkOwnership,fdOwnership
0,Tommy Pham,CWS,4400,2800,2.4,6.9
1,Max Scherzer,TEX,8800,9100,42.3,38.8
2,Freddie Freeman,LOS,5500,3700,5.5,11.5
3,Jose Altuve,HOU,5400,3700,4.1,12.6
4,Jd Martinez,NYM,5000,3300,4.8,15.0
5,Salvador Perez,KAN,4800,3500,2.9,8.6
6,Miguel Rojas,LOS,3700,2500,2.3,7.4
7,Charlie Blackmon,COL,4100,2700,2.1,5.9
8,Paul Goldschmidt,STL,4300,2800,3.2,9.7
9,Nolan Arenado,STL,3900,2800,2.1,6.6
10,Miles Mikolas,STL,6900,7900,24.4,15.7