I am trying to use importXML to get an automatic sector update and industry for my stocks in google sheets. In this case, in cell A5, is the name of the ticker. Normally, I would expect the following website:
https://eresearch.fidelity.com/eresearch/evaluate/snapshot.jhtml?symbols=AAPL
Where instead of AAPL, I wish to insert "A5"
Furthermore, I wish to receive the "Information Technology" in one formula and "Technology Hardware, Storage & Peripherals" in another subheading.
The formula I have created is the following:
=ALS(ISLEEG(A5);"";importxml("https://eresearch.fidelity.com/eresearch/goto/evaluate/snapshot.jhtml?symbols="&A5;"/html/body/table/tbody/tr/td[4]/table[2]/tbody/tr/td[1]/div[3]/div[8]"))
It is however, not working, can someone please help me?
Thanks much in advance.
I believe your goal as follows.
You want to retrieve the values of Information Technology and Technology Hardware, Storage & Peripherals.
In the case of https://eresearch.fidelity.com/eresearch/evaluate/snapshot.jhtml?symbols=AAPL, you want to retrieve, the values of Sector (GICS®) and Industry (GICS®).
In this case, I thought that the values might be able to be retrieved by a xpath. The sample xpath is as follows.
Sample xpath:
//div[#class='sub-heading']//h3[../span/a[text()='Information Technology' or text()='Technology Hardware, Storage & Peripherals']]
Modified formula:
=IMPORTXML(A1;"//div[#class='sub-heading']//h3[../span/a[text()='Information Technology' or text()='Technology Hardware, Storage & Peripherals']]")
In this case, the URL of https://eresearch.fidelity.com/eresearch/evaluate/snapshot.jhtml?symbols=AAPL is put in the cell "A1".
Result:
When you want to put the values to the columns, in this case, please use TRANSPOSE.
Note:
This xpath is for the URL of https://eresearch.fidelity.com/eresearch/evaluate/snapshot.jhtml?symbols=AAPL. So when you change the URL, the values you expect might not be able to be retrieved. So please be careful this.
Reference:
IMPORTXML
Related
I have a spreadsheet that is always updating with 50+ rows. I am trying to retrieve users who are Program Managers (PGM) by parsing text but I am having a hard time since the data is not consistent since it's filled out by 20+ users.
I googled "google sheet parse text" but it's giving me functions such as =SEARCH, =LENS, =LEFT which I cannot use since my data is not consistent. Are there any other options or am I out of luck and must parse my info manually? Thanks in advance.
Google Sheet Link Example
in C2 use:
=ARRAYFORMULA(IFERROR(REGEXEXTRACT(B2:B,"PGM:.*")))
You may try:
=byrow(B2:B,lambda(z,if(z="",,ifna(regexextract(z,"(PGM:.*)(?:\n|$)")))))
row 6 outcome is varying a bit
Is there a way to print out the GICS sector name for a specific share/ETF symbol in google sheets using the GOOGLEFINANCE commands or any other way?
Many thanks
I used this site to find several scraping methods to get data from finviz.
https://decodingmarkets.com/scrape-stock-data-from-finviz/
Extending their logic, I was able to get the company name, and the combined sector/subsector codes
(I originally used the website's scraping techniques to get Dividend data that GoogleFinance formula lacks...)
This formula gets the company name using US ticker symbol in cell C3:
=SUBSTITUTE(INDEX(IMPORTHTML("http://finviz.com/quote.ashx?t="&C3,"table",6),2,1),"*","")
Through trial and error, I found that table 6 has name and sectors. I then referenced the 2nd row and 1st column to get the name.
I found that row 3, column 1 has the sector, subsector and country combined as one value. They use a pipe | delimiter for each break.
Using the split function, I was able to split segment.
=SPLIT(SUBSTITUTE(INDEX(IMPORTHTML("http://finviz.com/quote.ashx?t="&C3,"table",6),3,1),"*",""),"|",true,true)
Its not available from Sheets
Check out the official docs:
https://support.google.com/docs/answer/3093281?hl=en
It has a lot of options but unfortunately, not that one.
If you think it would be useful, then make sure you file a feature request #
https://developers.google.com/issue-tracker
As for any other way
#GSee said it best here: https://stackoverflow.com/a/16525782/10445017
Following this post, where I had listed some of the interesting ETF1s I had found on some of the relevant forums, I received some valuable criticism. Now I want to use a Google spreadsheet to get the updated information of those ETFs in one place, and maybe use it for personal portfolio management. What I need:
preferably fetching data using the ISIN2 code, as the tickers/symbols are not really reliable and consistent between different databases and markets
The information I need are:
the current value of the ETF
the 1-year, 3-year, and 5-year performances/returns
current fund size
TER: Total Expense Ratio
TD: Tracking Differences
1-year volatility
For example, consider the "iShares Core MSCI World" ETF which is listed as "IWDA" on "Euronext Amsterdam" and an ISIN code of "IE00B4L5Y983". What I have read so far:
From this page and this post, I have used the GOOGLEFINANCE function to fetch the current price and some other information from Google Finance. However, I don't know how to fetch/calculate the 1/3/5-year performances, the fund size, TER, and the TD. Moreover, according to this comment, Google Finance, like many other Google products seem to be dying. So it would be great to have a more sustainable solution.
This post, suggests some syntax using index and IMPORTXML functions to fetch from etf.com. And this comment uses the same functions to fetch from nasdaq.com. But I couldn't make either to work, mainly because I don't know what symbol should I use.
This and this comments suggest the DGET and IMPORTDATA functions, to fetch data from api.iextrading.com, but I could not make it to work either.
This post and many other posts on the bogleheads.org forum, use all variants of syntax using the importHTML function to import and pars HTML tables from many different websites. There are many reliable websites that if I learn how to use this function I could fetch data from.
I would appreciate it if you could help me know how I can get the above information. Thanks for your kind support in advance.
P.S.1. From here, I was able to use the commands:
=INDEX(SPLIT(INDEX(importHTML(CONCATENATE("http://etfs.morningstar.com/quote-banner?&t=", C5), "table", 1),1,11), " "), 1, 3)
and
=INDEX(SPLIT(INDEX(importHTML(CONCATENATE("http://etfs.morningstar.com/quote-banner?&t=", C5), "table", 1),1,13), " "), 1, 2)
to pull Total fund size and TER consequently. However, they do not deliver data fro most of the ETFs and also I'm not sure how reliable this website is.
Footnotes:
1: Exchange-Traded Fund
2: International Securities Identification Number
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.
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.