How to web scrape Rotowire iframe table

Viewed 39

I am try to scrape tables from Rotowire. pd.read is only returning the Headers.

import pandas as pd

url = pd.read_html("http://www.rotowire.com/daily/mlb/optimizer.htm?site=DraftKings&sport=MLB")

# for idx, table in enumerate(url):
#     print("***************************")
#     print(idx)
#     print(table)

url[5]

Output:

Player  Team    Position    Salary  Fpts.   Val Min. %  Max. %  Exposure
0   NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 Answers

No idea what table you want, but you're not going to get anything from the static html response as the page is rendered through javascript. They do have some data you can access though. You'd have to work out the parameters:

import pandas as pd
import requests

url = 'https://www.rotowire.com/daily/tables/optimizer-mlb.php'
payload = {
'siteID': '1',
'slateID': '6441',
'projSource': 'RotoWire',
'rst': 'RotoWire'}

jsonData = requests.get(url, params=payload).json()
df = pd.DataFrame(jsonData)

Output:

print(df)
        id playerID rotoPlayerID  ... ie_green_lights ie_matchup_notes ie_volatility
0    12739    11095        12739  ...               0                              0
1    10510     4081        10510  ...               0                              0
2    16036     5163        16036  ...               0                              0
3    14194    10827        14194  ...               0                              0
4    14865    15463        14865  ...               0                              0
..     ...      ...          ...  ...             ...              ...           ...
687  14444    11330        14444  ...               0                              0
688  14440    18894        14440  ...               0                              0
689  14439    18905        14439  ...               0                              0
690  14435     5058        14435  ...               0                              0
691  17921    18828        17921  ...               0                              0

[692 rows x 99 columns]
Related