This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
Want to get yahoo data in google spreadsheet. I don;t want google data from google finance so please don't suggest that. I want yahoo finance data in spreadsheet.
I want data in the following spreadsheet which is editable:
https://docs.google.com/spreadsheets/d/1_MQyyaeEtGD0p9l7ncFqyLDWDKsnLNh2XBcH5CiHkF8/edit?usp=sharing
I want only specific column data for just first five days. the link for yahoo data extraction is:
https://in.finance.yahoo.com/quote/abb.BO/history/?guccounter=1
I have attached image for reference.
enter image description here
Please help how can I extract data specifically from one column.
I know I will have to use =transpose(importxml("url,xpath) but I am not sure about xpath.
You want to retrieve the latest 5 values of "close" which is yellow range. If my understanding is correct, how about this modification?
Modification points :
In your xpath, //[#class="Pb(10px) Ovx(a) W(100%)" cannot be used. If you want to retrieve values from class Pb(10px) Ovx(a) W(100%) of div, please modify "//div[#class='Pb(10px) Ovx(a) W(100%)']". This xpath includes the values you want. But it cannot retrieve only the latest 5 values of "close".
So I would like to propose "//tr[position()<6]/td[5]" as the xpath.
Modified formula :
=TRANSPOSE(IMPORTXML(A1,"//tr[position()<6]/td[5]"))
https://in.finance.yahoo.com/quote/abb.BO/history/?guccounter=1 is put in "A1".
Result :
If this was not what you want, I'm sorry.
Related
I’m trying to extract a single row from a table
When using the google sheet importhtml function, I get the whole table.
=IMPORTHTML("https://www.marketwatch.com/investing/stock/jwn/options?mod=mw_quote_tab", "table",1)
How can I extract just the row right above the word “ Current price as of “
So e.g. in this case the row will have the data below. (this data will change as the date changes)
quote 1.5 0.53 76 1.36 1.47 142 39 quote 0.88 -1.73 23
I have several urls to go thorough
So e.g if I put the following url then the row position will change.
https://www.marketwatch.com/investing/stock/ge/options
Any idea how to extract that just last row right above the word “ Current price as of “
When I saw the HTML data from the URL of https://www.marketwatch.com/investing/stock/ge/options, I thought that the value you expect might be able to be retrieved using IMPORTXML and a xpath. So in this answer, I would like to propose to use IMPORTXML.
Sample formula:
=IMPORTXML(A1,"//tr[td[1]/#class='acenter inthemoney'][last()]")
In this case, the URL of https://www.marketwatch.com/investing/stock/ge/options is put in the cell "A1".
Result:
Note:
This sample formula can be used for the current URL of https://www.marketwatch.com/investing/stock/ge/options. So when the URL is changed and the HTML structure is changed by updated of the site, the formula might not be able to be used. So please careful this.
Reference:
IMPORTXML
ImportHTML() simply allows you to read an (entire!) HTML table or list into your Google sheet.
If you want to filter or manipulate the imported data, then you'll need to use other Google Sheets functions. These are documented here:
Google Sheets function list
Alternatively, you might want to "import" input one sheet, then select certain data into another, separate sheet:
Get data from other sheets in your spreadsheet
Here are some examples for "filtering" your data:
FILTER function
First post on Stack Overflow! I have minimal IT/Dev background, and I was just trying to learn how to data scrape using the Import XML function in Google Sheets to get a little experience with the function and I've ran into a speed bump, hoping you can help!
I've been successful in my attempts to pull the data I would like so far, but there is a tiny amount of information I would also like to extract, but can't really figure it out thus far. I can see the information in Google DevTools. (Screenshot attached)
The data is stored in the Class definition line and it defines the time Last Seen, accessible one of two ways.
URL : https://us.tamrieltradecentre.com/pc/Trade/SearchResult?ItemID=11807&SortBy=Price&Order=asc
Desired function from ImportXML would be to pull the text, or the URL Extension - With the information of one of those two pieces of information
Thanks for your help!
*EDIT Added Google Sheets Screenshot
Devtool Screenshot
Google Sheets Screenshot
Red Circles for Values I Would Like To Import
You want to retrieve the values of "Last seen" like "1 Hour ago" from the URL using IMPORTXML.
When I checked the site of the URL, it was found that at the URL you want to use, the values like "1 Hour ago" are put using Javascript. In this case, unfortunately, that cannot be retrieved using IMPORTXML. Because IMPORTXML cannot evaluate Javascript.
I have a simple personal money tracker based on Google form for data input and spreadsheet for calculating, statistics and so.
Everything works just fine but now I need workaround to display the last five entries in sheet that contain raw data from Google form.
This is what the sheet looks like:
What I want to do is create new spreadsheet which displays the last five entries from the sheet with data from Google form. Please help me with right formula for this.
P.S: Would be perfect display this information right in Google form that I used to enter data but as far as I know its impossible.
If there are no gaps in the time column, you could try
=query(A:D,"select * offset "&count(A:A)-5)
This question already has answers here:
Scraping data to Google Sheets from a website that uses JavaScript
(2 answers)
Closed last month.
I'm trying to import current stock price from yahoo finance. I used a formula from some website and it partially work. I only know how to tell it to look for a specific query and it worked fine for some other data point I need but the price change query changes from
"Fw(500) Pstart(10px) Fz(24px) C($dataRed)"
to
"Fw(500) Pstart(10px) Fz(24px) C($dataGreen)"
depending if the price is up or down for the day.
How do I modify the formula I'm using below to use the "or" operator in this case? so that it will pull the price down whether the stock is up or down for the day. Thanks!
Formula I'm using:
=IMPORTXML("https://finance.yahoo.com/quote/IBM","//span[#class='Fw(500) Pstart(10px) Fz(24px) C($dataRed)']")
I noticed the other answers did not work for me (they may have worked in the past), so I decided to post this solution. Just put the ticker in cell A1 and one or both of the below formulas somewhere else.
Price:
=IFNA(VALUE(IMPORTXML("https://finance.yahoo.com/quote/" & A1, "//*[#class=""D(ib) Mend(20px)""]/span[1]")))
Change:
=IFNA(VALUE(REGEXEXTRACT(IMPORTXML("https://finance.yahoo.com/quote/" & A1,"//*[#class=""D(ib) Mend(20px)""]/span[2]"), "^.*?\s")))
Currently using googlefinance but find it does not update often enough even when updates set to every minute so currently testing if below will allow updates at least with an F5 press within the sheet
This brings in the price and other information (dated 2022/09/27)
=IMPORTXML("https://finance.yahoo.com/quote/SAVA/", "//*[#id=""quote-header-info""]/div[3]/div[1]/div[1]")
If you just want the price: =IFNA(VALUE(IMPORTXML("https://finance.yahoo.com/quote/" & $A1, "//*[#class=""D(ib) Mend(20px)""]/span[1]")))
You could use a more dynamic/generic xpath that doesnt require such specific paths such as this:
This one pulls in both the price and the change:
=ARRAY_CONSTRAIN(transpose(IMPORTXML("https://finance.yahoo.com/quote/IBM:,"//*[#class='Mt(6px)']//span")),1,2)
If you just want the price:
=trim(IMPORTXML("https://finance.yahoo.com/quote/IBM","//*[#class='Mt(6px)']//span"))
If you just want the change:
=IMPORTXML("https://finance.yahoo.com/quote/IBM","//*[#class='Mt(6px)']//span[2]")
Sadly Yahoo Finance changes the XML/HTML structure of its website quite often. The one that works for now is:
=IMPORTXML("https://finance.yahoo.com/quote/IBM/", "//*[#id=""quote-header-info""]/div[3]/div[1]/div/span[1]")
You may always open the HTML structure and use the developer tools to find and copy the X-path.
P.S.1. Though there seem to be a bug and the function can't retrieve data from URLs where there is a dot/point/period "." in the name.
P.S.2. The IMPORTHTML() function can't also fetch the latest price from Yahoo Finance because the information is neither in a table nor a list. You can try the scripts from this page and this page to list all the tables and lists.
I want to retrieve only sheet's data from a spreadsheet with formatting.
How to achieve the same with Sheets Api?
It isn't clear from your question just what kind of data you want to get. Do you want to retrieve the values as they're formatted in the Google Sheets UI? If so, then use the spreadsheets.values.get API. The parameter valueRenderOption controls how the values are formatted. By default, the value is FORMATTED_VALUE, which will return the data as it's formatted in the Sheets UI. Other values are listed on the ValueRenderOption reference page. See the Basic Reading sample for more information.
If you want to retrieve the information about the format itself, use the spreadsheets.get API. Format information is in the response's CellData (at sheets.data.rowData.values), in both the userEnteredFormat and effectiveFormat fields.