=importhtml Google Sheets table - google-sheets

Unfortunately I don't know how to source this and was wondering if someone could show me how. I am trying to learn hear so the correct answer is great, but the "How to get the answer" is more important to me.
I am using google sheets, and looking to bring in a table or data point from a website. I know =importhtml works for this but I don't know how to tell it what to get, I just keep getting people giving me the answers instead of the how too.
The current one I am looking for is the website "https://www.marketbeat.com/stocks/NASDAQ/TSLA/earnings/" Using TSLA as the example stock. I am looking to bring in the table that has all the earnings dates. The header is "TESLA (NASDAQ:TSLA) EARNINGS HISTORY BY QUARTER". I am just looking for all the dates in that table, but if it is easier to bring in the whole table I'll do that instead. But I know these websites update and that can change how the =importhtml works, so I would like to be able to fix it myself.
Also I am on a Mac
Thanks for any help.

=index(IMPORTHTML("https://www.marketbeat.com/stocks/NASDAQ/TSLA/earnings/","table",2),,1)
"2" is the table index for the one you are looking for and "1" is the column that you need.
Delete 1 and you will get the whole table.
=index(IMPORTHTML("https://www.marketbeat.com/stocks/NASDAQ/TSLA/earnings/","table",2))

Related

Creating a single all day calendar event from a single google sheet

I want to create a single all day calendar event from a single google sheet.
I have been racking my brain over this for a couple days and its getting old. All the examples I have seen and tried to adapt use a range of cells to create multiple calendar events. I want to do something like this, every sheet is an order form, and every order will have its own sheet, so every sheet will have a single due date, and a single job name, and each sheet needs to be added to the calendar. And every time I need to make a new order I will copy the blank sheet, fill it out, and click a button to add that new order to the calendar. So every time I have thought I had it figured out, and I modify code I fond online to do this, I get errors, I try to fix them, I get others, and I just cant seem to get this stupid thing working!
I feel like what I want to do is doable, and should be pretty simple, I'm just lost on this. I am not new to coding, generally, but I have not coded is this format, and I honestly don't understand a lot of the callouts and what they are doing.
Any help? Please?
I have tried adapting code I have found across the internet, such as the code found here

Solved: Extract date from my Substack webpage to Google Sheets

longtime lurker, first-time poster. I usually solve my issues & upvote without needing to post, but I've been stumped all weekend!
Edit: Erik solved it:
I was looking for an answer to extract the "datePublished" or "dateModified" from a Substack article in a Google Sheet.
Goal: This will tell me when it was the last date/time I updated, for example, my PS5 restock guide, my Walmart PS5 restock guide, etc. If it's too stale, I try to add relevant information. Having it in Google Sheets makes it streamlined as there are dozens of guides.
Test Google Sheet:
https://docs.google.com/spreadsheets/d/1hLBFMWCTc2hpC-1C8Sxd5OVREdNHTVTtrJsAAU5Jl94/edit#gid=0
I've done this before for other sites I've worked at, but there appears to be no date in the meta data on Substack :/ (I could be wrong, as I'm no expert at reading XPATH)
I do see this in the body for the linked example:
<time datetime="2022-07-29T11:52:00.000Z">Jul 29</time>
I've been trying things like this (where E17 is where I put the article URL in Google Sheets) to no effect.
=REGEXEXTRACT(IMPORTXML(E17, "//time[#datetime='datePublished']/#content"), "(.+)T")
I've been mostly working off of this StackOverflow solution, but I haven't been able to apply the same finding to Substack's formatting.
If you want to grab it directly using a Google Sheets formula, this should work for you:
=ArrayFormula(IFERROR(VLOOKUP("*",FLATTEN(IFERROR(REGEXEXTRACT(IMPORTXML("https://www.theshortcut.com/p/ps5-restock","//div[2]"),"Swider(.?.?.?.?\d\d{1}[hrago\s]*)"))),1,FALSE),"???"))
To set realistic expectations, I usually can't invest this much time into working out such a solution on this forum. But I'm on vacation at the moment and filling time while my guest is otherwise occupied.
One further note: this is specific to the two sites you gave as examples. It will only work for sites where the second <div> holds this information and only where the data exists as strings exactly like those found on these two sites (including the poster's last name as "Swider").
ADDENDUM:
Looking at this further, did you try simply the following?
=IMPORTXML(C2, "//time")
(assuming your URL is in C2, etc.)
This seems to work for me, given that it appears the date/time data you want is contained within the first <time> element on the web page.

SUMIFS Issue on Google Sheets

I'm using the following formula to pull in data from the Purchases sheet tab on Google Sheets within our spreadsheet.
=SUMIFS(PURCHASES!$H$2:$H$2000,PURCHASES!$F$2:$F$2000,"101")
What's happening though is every entry is causing the "2" and the "2000" to increase by 1. I don't want that, because data could then be missed (and it is). Any ideas?
I really need help. Thank you so much in advance!
We cannot know exactly what is going on, because we can't see your sheet. But two common ways to fix the issue are these:
1.) Use INDIRECT for your references:
=SUMIFS(INDIRECT("PURCHASES!H2:H2000"),INDIRECT("PURCHASES!F2:F2000"),"101")
2.) Include the entire column as the reference:
=SUMIFS(PURCHASES!$H:$H,PURCHASES!$F:$F,"101")
There are other options as well, but they'd require our being able to view your sheet via a shared link.

Yahoo Finance Dividend History Table Missing

I've been using the Yahoo Dividend History table for a stock app I've created for many years. Today it was missing, screwing up the whole app.
Check for yourself here:
https://developer.yahoo.com/yql/console/#h=select+Symbol%2C+Dividends%2C+Date+from+yahoo.finance.dividendhistory+where+startDate+%3D+%22%22+and+endDate+%3D+%22%22+and+symbol+in+(%22GRX%22)
And here is a picture proving it.
I asked this question a while back and then it turned out that it either showed up again or I had made a mistake. I'm not certain which. This time I know for sure it's missing.
So two questions: 1) Why would it go missing and can anyone fix it? Who can? 2) Is there an alternative source I can use instead. Maybe a Div History api for Yahoo or from somewhere else?

Performing Google Search In Spreadsheet And Scraping The SERP Data

I hope that you guys are fine. I want to build a simple spreadsheet and I thought I could be able to make one but blank sheet looks horrible to me. I am sure that you guys are kind enough to help me out.
I want to perform multiple Google search queries in Google spreadsheet and want to parse results of each search (top 10 results of each search)
Something like this: https://www.youtube.com/watch?v=tBwEbuMRFlI
But when I tried his given formula in description to play test, Google returned #Error to me, I don't know why.
Can you guys please help me out in making a simple spreadsheet compatible for multiple queries at once? Like one column for keywords (where I could paste my list of keywords) and then 10 columns of search results. All results for one keyword should come in one row
Something like this:
My 1st Example Query = 1st search result, 2nd search result, 3rd result and so on.
My 2nd Example Query = 1st search result, 2nd search result, 3rd result and so on.
It must be easy to code but yeah, it might be time-consuming and I would be very grateful if anyone of you could help me about it.
Looking forward to your help guys.
The problem is that you want to scrape out of Spreadsheets, that's a bad approach and is almost certainly not going to work. Even if you manage to write a scraper inside that limited environment it will easily be spotted by Google.
As you said time is not a problem, I would suggest another route.
Use a backend tool/script that scrapes the data
Use a backend tool/script that creates/modifies the Google spreadsheet
You can run such a script(s) manually on your PC or from a server full automated using a scheduler/cron job.
To create/modify spreadsheets look here: How do I access the Google Spreadsheets API in PHP?
To scrape Google look here: Is it ok to scrape data from Google results?
So this is PHP as language of choice but you can do the exactly same in Java or Python or C#
There is a third party solution like SerpApi you could use for this. It's a paid API with a free trial.
Google Sheets Add-on: SerpApi - Search Engine Results and Ranks
Example code to extract title from the first result:
=SERPAPI_RESULT("engine=google&q=coffee&location=Austin, Texas, United States&google_domain=google.com&gl=us&hl=en", "organic_results.0.title")

Resources