2013-05-12 4 views
13

Google App EngineのFinance APIをGoogleが削除したことに気付きました。私が望むのは、Googleファイナンスのポートフォリオにある株価指数のリストだけです。 APIが削除されているので、エンドユーザーのポートフォリオからこのデータを引き出す方法はありますか?私はログインとパスワードを知っているので、手動で取得しようとしています(例えば、自分自身です)。ユーザーのGoogle Financeポートフォリオにアクセスするには

Googleサービスにログインして、手動でcurlで検索する方法はありますか?ログインして自分のポートフォリオページに移動し、ソースを取得することが可能なようです。

私は、次のコードを試してみました:

#!/bin/bash 

function ClientLogin() { 
    read -p 'Email> ' email 
    read -p 'Password> ' -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&pid=1" &> output.html 
} 

GetFinance 

しかし、このコードはのみのログインに私に語ったページを取得するソリューションはカールを使用する必要はありませんが、それは使用して自動検索でなければなりません。いくつかのスクリプト言語。 x4avierへ


おかげで、私はcasperjsについて学んだと、Googleサービスのログインページをロードするための簡単なスクリプトを作成し、ユーザ名とパスワードを入力し、Googleのファイナンス・ポートフォリオを取得することができました。私はこれが他のGoogleのサービスとページでうまくいくと確信しています。私はportfolio.htmlにポートフォリオのhtmlを保存します。うまくいけば、これは誰かにも役立ちます。

var fs = require('fs'); 
var failed = []; 
var links = [ 
    "https://www.google.com/finance/portfolio?action=view&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: '[email protected]', 
     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(); 
+0

http://stackoverflow.com/questions/10040954/alternative-to-google-finance-api –

+0

Yahoo finance APIもユーザーのポートフォリオへのアクセスを許可していません – gnychis

+0

クッキーを保存し、実行するクライアントを実装する必要がありますjavascriptを使用し、Googleアカウントにログインする場合はリダイレクトを処理します。どうしてティッカーシンボルを手動でエクスポートしてパブリックAPIをスクラップして個々の引用符を取得するのではなく、パブリックAPIはまだ動作しており、Googleのポリシーに基づいて少なくともさらに3年間は有効です。 https://www.google.com/finance/info?q=NASDAQ:AAPL –

答えて

5

casper.jsのようなヘッドレスブラウザの使用を検討する必要があります。

これで、Googleにログインし、Google Financeにアクセスして、ページまたは特定のCSSセレクタのHTMLを取得できます。あなたがfill()機能を使用する意志ログインに

、それは次のように動作します。

casper.start('http://admin.domain.tld/login/', function() { 
    this.fill('form[id="login-form"]', { 
     'username': 'chuck', 
     'password': 'n0rr1s' 
    }, true); 
}); 

casper.run(); 

その後、あなたは以下のように動作し、ページとgetHTML()で特定のコンテンツを解析することができます。

casper.then(function() { 
    this.echo(this.getHTML('h1#foobar')); // => 'The text included in the <h1 id=foobar>' 
}); 

CasperJsはクッキーで動作し、複数のページを探索します。あなたのニーズに合っているはずです。

希望します。

1

正確に取得する情報はありますか?

これは、Pythonのurllibはを使用して、私は自分が投稿し、別のフォーラムのウェブサイト上でメッセージを取得するためにそれをやった http://docs.python.org/2/library/urllib2.html http://www.crummy.com/software/BeautifulSoup/bs4/doc/

をbeautifulsoupことを行うには非常に簡単です。クールではない唯一のことは、検索したい要素のIDをハードコードする必要があることです。

は、ここで私は、私はGoogleのログインに必要な情報の一部を埋め、ログイン一部

#!/usr/bin/python 

import urllib 
import urllib2 
import cookielib 
import BeautifulSoup 

url = "https://accounts.google.com/ServiceLogin?hl=en"; 
values = {'Email': '[email protected]', 'Passwd' : '', 'signIn' : 'Sign in', 'PersistentCookie' : 'yes'} # The form data 'name' : 'value' 

cookie = cookielib.CookieJar() 
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie)) 
data = urllib.urlencode(values) 
response = self.opener.open(url, data) 
print response 

のために何をしたかのサンプルです。しかし、私がPOST要求をチェックしたときに、値dictに値を追加する必要があるかもしれない他の値がありました。私はあなたが実際にフォームを送信する前にこの値を取得するBeautifulsoupを使用してログインページを解析する必要があります推測

dsh:5606788993588 
hl:en 
checkedDomains:youtube 
checkConnection:youtube:47:1,youtube:46:1 
pstMsg:1 
GALX:YU6dyLz2tHE 
pstMsg:0 
dnConn: 
checkConnection: 
checkedDomains:youtube 
timeStmp: 
secTok: 
_utf8:☃ 
bgresponse:!A0LP9ks4H06eS0R0GKgonCCotgIAAAAiUgAAAAkqAOjHBiH2qA-EIczqcDooax5q8bxis... 
Email:****@gmail.com 
Passwd:mypassword 
signIn:Sign in 
PersistentCookie:yes 
rmShown:1 

は、ここで私が撮影しPOSTリクエストです。もしあなたがむしろそれを使いたいならば、あなたが望むものをBeatifulsoupを使ってポートフォリオページを解析するのであれば、上記のキャスターの例がそれを自動的に行うのだろうか?

関連する問題