0
votes

I'm trying to use the IMPORTDATA function in Google Sheets to download stats from baseball-reference.com.

For example, if I want the Team Standard Batting table from:

https://www.baseball-reference.com/leagues/MLB/2020.shtml

I click on the "Share & more" > "Copy Link to Table to Clipboard" to get:

https://www.baseball-reference.com/leagues/MLB/2020.shtml#teams_standard_batting

Then, in A1 of my otherwise empty Google Sheet, I'm inputting:

=IMPORTDATA("https://www.baseball-reference.com/leagues/MLB/2020.shtml#teams_standard_batting")

however, I'm getting #REF with the following error message:

"Result was not automatically expanded, please insert more columns (86)."

2

2 Answers

1
votes

IMPORTDATA needs to be almost always restricted

try for starters:

=ARRAY_CONSTRAIN(IMPORTDATA("https://www.baseball-reference.com/leagues/MLB/2020.shtml#teams_standard_batting"); 5000; 20)

this will import you the source code of that site.


update:

try:

=IMPORTHTML("https://www.baseball-reference.com/leagues/MLB/2020.shtml#teams_standard_batting", 
 "table", 1)

enter image description here

0
votes

You need to add another 86 columns, like the warning is telling you