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)."
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)
You need to add another 86 columns, like the warning is telling you
Related
I am trying to import data for range A1:J from the sheet named "BODY COVER STOCK" using ImportRange function the first Column shows NA and Column H,I,J shows blank under headings. Can anyone help me out in finding where I am going wrong with this.
Data SpreadSheet link - https://docs.google.com/spreadsheets/d/1HzSslzdKFtbxEdPQPX5Ox0Cq2NNaqRViYX3ookQ4I1w/edit#gid=0
Target SpreadSheet Link -
https://docs.google.com/spreadsheets/d/18zkwzlPi1PREKW8EG71NGGokOULKRMqAdEck-u3YvHA/edit#gid=0
Thanks in advance.
Formulae I am using -
=IMPORTRANGE("https://docs.google.com/spreadsheets/d/1HzSslzdKFtbxEdPQPX5Ox0Cq2NNaqRViYX3ookQ4I1w/edit#gid=0","BODY COVER STOCK!A1:J")
Data Sheet Image -
Target Sheet Image -
could ba a result of excessive usage of dependency...
if you have editing access to Data SpreadSheet try adding an intermediate (new) sheet with this in A1:
={BODY COVER STOCK!A1:J}
and then import that new sheet with IMPORTRANGE
=IMPORTRANGE("1HzSslzdKFtbxEdPQPX5Ox0Cq2NNaqRViYX3ookQ4I1w", "new sheet!A1:J")
I'm trying add easy updating prices into a google sheet.
I need the market price from
//*[#id="app"]/div/section[2]/section/div[1]/section[3]/div/section[1]/ul/li[1]/span[2]
https://www.tcgplayer.com/product/242811/pokemon-celebrations-celebrations-elite-trainer-box?Language=English
I need it to display just the one number from the XPath to a cell, and I can't seem to figure out where I am going wrong. I've been using the IMPORTXML function and it won't return a value.
=IMPORTXML(A2,"//*[#id='app']/div/section[2]/section/div[1]/section[3]/div/section[1]/ul/li[1]/span[2]")
where A2 is the URL.
In your situation, it seems that the value of the market price cannot be directly retrieved from the URL of https://www.tcgplayer.com/product/242811/pokemon-celebrations-celebrations-elite-trainer-box?Language=English. But, fortunately, it seems that that value can be directly retrieved from the endpoint of API. So, how about the following sample formula?
Sample formula:
=REGEXEXTRACT(JOIN(",",IMPORTDATA(A1)),"marketPrice:(.+?),")*1
or
=REGEXEXTRACT(QUERY(TRANSPOSE(IMPORTDATA(A1)),"WHERE Col1 matches 'marketPrice.+'"),"marketPrice:(.+)")*1
The cell "A1" has the URL of https://mpapi.tcgplayer.com/v2/product/242811/details.
In the case of https://www.tcgplayer.com/product/242811/pokemon-celebrations-celebrations-elite-trainer-box?Language=English, please use 242811 from the URL to the endpoint of API like https://mpapi.tcgplayer.com/v2/product/242811/details.
Result:
Note:
The value from the URL is JSON data. In this case, the following custom function can be also used. In this case, please copy and paste the following script to the script editor of Spreadsheet and save the script. And please put a custom function of =SAMPLE("url") to a cell.
const SAMPLE = url => JSON.parse(UrlFetchApp.fetch(url).getContentText()).marketPrice;
References:
IMPORTDATA
REGEXEXTRACT
Custom Functions in Google Sheets
it's not possible to scrape JS content into google sheets:
Can you please help me with the index match formula with Google sheets on 2 different workbooks? I know the formula on a regular excel sheet but it just won't do the same with google sheets.
I tried the same formula with the regular excel sheet but it just won't work.
try:
=IMPORTRANGE("1VYCPRlno-upguZFmf-dgVG8pXxkXXTx-OWt_VBv4d5c", "Sheet1A:Z")
note: chenge sheet name if needed
note2: first you will see ref error. hover your cursor over it and a button will popup. click on it to authorize the connection/link between your two spreadsheets
I shared a Google sheet to another user. The other user is able to open it, but when they go to make a copy everything comes up as "value" even on the original user's sheets.
It's because the copy of the sheet is not linked with the referenced sheet in IMPORTRANGE. Every time you use IMPORTRANGE you need to authorize the link between those two given sheets. without that authorization, you got errors as you mentioned.
To resolve this you have two options:
if the referenced sheet is public you just need to run simple IMPORTRANGE in any cell and authorize the connection between the referenced sheet and copy of the sheet. you will get #REF! error on which you need to hover mouse cursor and a magic button will pop up
=IMPORTRANGE("ID-OR-URL", "Sheet1!A1:A10")
if the referenced sheet is private, you need to ask the original owner for permission and authorize it as mentioned above
UPDATE:
=QUERY({
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","January!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","February!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","March!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","April!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","May!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","June!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","July!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","August!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","September!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","October!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","November!A:Z");
IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","December!A:Z")},
"where Col3 = 'Bob'
and Col1 is not null")
This is happening because you requesting some particular columns before you give access to the new spreadsheet.
Simply go to any other empty cell (i.e. the cell under that one you mentioned above.)
Write a simple IMPORTRANGE function like this:
=IMPORTRANGE("1X_NBWq1m9iBxvYXhy2wcttHanvPFPlAOJWgbbKbJimQ","January!A:Z")
Then click again the cell you just filled andclick "Allow Access".
After access allowed empty the cell you just created and you will propably be able to get the first cell formula working.
Which is the best way to test if a sheet exists or not in a Google spreadsheet, only using formulas (by a script it is easy, but I need speed!)?
For example, using =error.type('mysheet'!A1) gives error 4, but I am looking for something more specific... (error 4 could mean also something else...)
Many thanks
I'm using =IF(ISREF('Nov 17'!BT39), 'Oct 17'!BT39, "") to determine if a sheet exist. Maybe that will help.
Checks whether a value is a valid cell
reference.
My sheet time recording has the cell F5 (="October 2017").
Maybe you need to build your sheet name from a string. If so, use INDIRECT to build the sheet path. =IF(ISREF(INDIRECT("'" & LEFT(F5, 3) & " ''" & Right(F5, 2) & "'" & "!BT39")), TRUE, FALSE)
That gives me that path to Oct '17, my reference sheet, which I want to check if exist or not.
Greetings