title: way to access user's Google Finance portfolio?
body: <p>I noticed that Google removed the Finance API for Google App Engine.  All I want is a list of stock tickers that they have in their Google Finance portfolio.  Is there any way to still pull this data from the end user's portfolio, given that the API has been removed?  I'm trying to manually retrieve it given that I know the login and password (e.g., it's my own).  </p>
  
  <p>Is there any way to retrieve it manually through curl, by logging in to the Google services?  It seems like it should be possible to log in and go to my portfolio page, retrieving the source.</p>
  
  <p>I have tried the following code:</p>
  
  <pre><code>#!/bin/bash
  
  function ClientLogin() {
    read -p 'Email&gt; ' email
    read -p 'Password&gt; ' -s password
    local service=$1
    curl -s -d Email=$email -d Passwd=$password -d service=$service https://www.google.com/accounts/ClientLogin | tr ' ' \n | grep Auth= | sed -e 's/Auth=//'
  }
  
  function GetFinance() {
    curl -L -s -H "Authorization: GoogleLogin auth=$(ClientLogin finance)" "http://www.google.com/finance/portfolio?action=view&amp;pid=1" &amp;&gt; output.html
  }
  
  GetFinance
  </code></pre>
  
  <p>However, this code only retrieves a page that tells me to log in. The solution does not need to use curl, but it must be an automated retrieval using some scripting language. </p>
  
  <hr>
  
  <p>Thanks to x4avier, I learned about casperjs and was able to write a quick script to load the Google services login page, enter the username and password, and then fetch the Google Finance portfolio.  I'm sure this would work with any other google service and page.  I save the html of the portfolio to portfolio.html.  Hopefully this helps someone else also.</p>
  
  <pre><code>var fs = require('fs');
  var failed = [];
  var links = [
      "https://www.google.com/finance/portfolio?action=view&amp;pid=13"
  ];
  
  var casper = require('casper').create({
      verbose: true,
      logLevel: 'debug',
      pageSettings: {
           loadImages:  false,         // The WebPage instance used by Casper will
           loadPlugins: false,         // use these settings
           userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.94 Safari/537
      }
  });
  
  // print out all the messages in the headless browser context
  casper.on('remote.message', function(msg) {
      this.echo('remote message caught: ' + msg);
  });
  
  // print out all the messages in the headless browser context
  casper.on("page.error", function(msg, trace) {
      this.echo("Page Error: " + msg, "ERROR");
  });
  
  var url = 'https://accounts.google.com/ServiceLogin?service=finance';
  
  casper.start(url, function() {
     // search for 'casperjs' from google form
     console.log("page loaded");
     this.test.assertExists('form#gaia_loginform', 'form is found');
     this.fill('form#gaia_loginform', {
          Email: 'youraccount@gmail.com',
          Passwd:  'yourpass'
      }, true);
  });
  
  casper.each(links, function(casper, link) {
      this.then(function() {
          this.test.comment("Loading " + link);
          start = new Date();
          this.open(link);
      });
      this.then(function() {
          var message = this.requestUrl + " loaded";
          if (failed.indexOf(this.requestUrl) === -1) {
              this.test.pass(message);
              fs.write('portfolio.html',this.getPageContent(),'w');
          }
      });
  });
  
  casper.run();
  </code></pre>