Portal Forums Links Register FAQ Community Calendar Log in

Join Early Retirement Today
Reply
 
Thread Tools Display Modes
Updated TSP screen scraping function
Old 07-14-2020, 08:15 AM   #1
Give me a museum and I'll fill it. (Picasso)
Give me a forum ...
donheff's Avatar
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 11,331
Updated TSP screen scraping function

I have screen scraped TSP prices for my Google Spread Sheet for quite some time. About a year ago or so they changed their tables and I could no longer figure out how to import the xml data. Cathy63 helped me out and I got it working again. A couple of weeks ago they added new lifecycle funds and altered the tables. I was able to figure out how to modify my import statement to reference the new table columns. But now they changed the page structure and the table structure and I can't figure it out.

Cathy63, if you are out there can you take a look?

This is the function that was working until last week:

=importxml("https://www.tsp.gov/InvestmentFunds/FundPerformance/index.html","//table[1]/tr[2]/td[12]")

This is a modified function that uses the new page but doesn't work:

=importxml("https://www.tsp.gov/fund-performance/share-price-history/","//table[1]/tr[2]/td[12]")

The page on the tsp site is: /fund-performance/share-price-history/

I will post this as is and see if this stuff displays properly - its been a while and I can't remember what I needed to do to get this stuff to show up properly on erdotorg.
__________________
Idleness is fatal only to the mediocre -- Albert Camus
donheff is offline   Reply With Quote
Join the #1 Early Retirement and Financial Independence Forum Today - It's Totally Free!

Are you planning to be financially independent as early as possible so you can live life on your own terms? Discuss successful investing strategies, asset allocation models, tax strategies and other related topics in our online forum community. Our members range from young folks just starting their journey to financial independence, military retirees and even multimillionaires. No matter where you fit in you'll find that Early-Retirement.org is a great community to join. Best of all it's totally FREE!

You are currently viewing our boards as a guest so you have limited access to our community. Please take the time to register and you will gain a lot of great new features including; the ability to participate in discussions, network with our members, see fewer ads, upload photographs, create a retirement blog, send private messages and so much, much more!

Old 07-14-2020, 10:32 AM   #2
Thinks s/he gets paid by the post
 
Join Date: Mar 2013
Location: Coronado
Posts: 3,707
Well, this is a pain! They have changed the way they bring the data into the page, and I don't think you can scrape it directly any more. It's now in a plain text/CSV file and I don't see a way to get a single number without importing the whole thing. Maybe there is someone else who has a different idea of how to do this.

This formula will bring in yesterday's prices for all the funds: =importdata(concatenate("https://secure.tsp.gov/components/CORS/getSharePricesRaw.html?InvFunds=1&startdate=",year (today()-1),text(month(today()-1),"00"),text(day(today()-1),"00")))

If you put it in a new tab, say it's named Sheet2, and you want the G Fund's price, then you can just copy the cell you're interested in as =Sheet2!B2

Here's a screenshot of how it looks, just in case some characters don't show up correctly above.

If you want the numbers for today, then just change the three places where I put "today()-1" to "today()". I used yesterday to test this because there was no data available for today yet.
Attached Images
File Type: jpg Annotation 2020-07-14 092047.jpg (43.2 KB, 27 views)
cathy63 is offline   Reply With Quote
Old 07-14-2020, 11:04 AM   #3
Give me a museum and I'll fill it. (Picasso)
Give me a forum ...
donheff's Avatar
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 11,331
Thank you. I figured they would eventually break things. I will fool around with this a bit. If worse comes to worse I can just put a proxy fund ticker into my speadsheet which I did in years past. I don't need precision.
__________________
Idleness is fatal only to the mediocre -- Albert Camus
donheff is offline   Reply With Quote
Old 07-14-2020, 12:53 PM   #4
Give me a museum and I'll fill it. (Picasso)
Give me a forum ...
donheff's Avatar
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 11,331
Thank you Cathy. Your approach works fine. I will have to send you a retainer.
__________________
Idleness is fatal only to the mediocre -- Albert Camus
donheff is offline   Reply With Quote
Old 07-14-2020, 02:30 PM   #5
Thinks s/he gets paid by the post
zinger1457's Avatar
 
Join Date: Jul 2007
Posts: 3,229
It's been awhile since I looked at the TSP site, it certainly has changed a lot recently. Are you importing the prices for all the TSP funds into your spreadsheet or just the ones you own? Trying to understand the benefit of importing that data. I just look up the latest share price for the TSP Funds I have (currently only two) and copy/paste that into my spreadsheet, takes about 15 seconds.
zinger1457 is offline   Reply With Quote
Old 07-14-2020, 02:40 PM   #6
Dryer sheet wannabe
 
Join Date: May 2018
Location: Bend
Posts: 17
I also ran into the issue of importing TSP share prices with the new TSP web page. Found this thread on Bogleheads. Used the command in this thread and it worked!

https://www.bogleheads.org/forum/viewtopic.php?t=141547
kobedog is offline   Reply With Quote
Old 07-14-2020, 02:43 PM   #7
Give me a museum and I'll fill it. (Picasso)
Give me a forum ...
donheff's Avatar
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 11,331
Using Cathy’s function, I am importing the previous day’s table of prices into a separate sheet (tab). I then reference the few cells I want in my primary sheet. The primary sheet lists all of my wife and my holdings and updates prices at the end of day. I update the share numbers occasionally to account for dividends and sales. Otherwise it auto updates.
__________________
Idleness is fatal only to the mediocre -- Albert Camus
donheff is offline   Reply With Quote
Old 07-14-2020, 03:38 PM   #8
Thinks s/he gets paid by the post
 
Join Date: Mar 2013
Location: Coronado
Posts: 3,707
The BogleHeads solution also works, and it doesn't require importing into an extra tab, so it might be easier to use.
cathy63 is offline   Reply With Quote
Old 07-15-2020, 09:01 AM   #9
Give me a museum and I'll fill it. (Picasso)
Give me a forum ...
donheff's Avatar
 
Join Date: Feb 2006
Location: Washington, DC
Posts: 11,331
I inserted Bogleheads code for a couple of funds and left Cathy's approach for others. That way I have reminders of both.

Thanks to both of you.
__________________
Idleness is fatal only to the mediocre -- Albert Camus
donheff is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Screen scraping function for return YTD? donheff FIRE and Money 83 02-20-2019 02:04 PM
Scraping By on $250K/Year Amethyst FIRE and Money 105 03-23-2011 07:03 PM
Scraping off the dependents cute fuzzy bunny Health and Early Retirement 5 07-13-2008 02:11 PM
Scraping by on $150,000 a year Milton FIRE and Money 11 10-13-2007 02:43 PM
Scraping Wallpaper - - Oh, Joy? :) W2R Other topics 41 09-24-2007 10:38 AM

» Quick Links

 
All times are GMT -6. The time now is 10:13 PM.
 
Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2024, vBulletin Solutions, Inc.