1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Google Spreadsheet で日本株の会社名と株価を取得する

Last updated at Posted at 2025-09-15

日本株の株価を取得する関数の追加

  1. Google Spreadsheet で、データ → 名前付き関数 を選択
  2. 新しい関数を追加 をクリック
  3. 関数名に GET_STOCK_PRICE_JP を入力 (名前はなんでも良い)
  4. 引数のプレースホルダーに ticker と入力して、リターン
  5. 数式の定義に、以下を張り付ける
    =VALUE(SUBSTITUTE(IMPORTXML("https://www.google.com/finance/quote/" & ticker & "?hl=ja","//*[@class=""YMlKec fxKbKc""]"), "¥", ""))
    
  6. 次へ作成をクリックして保存
  7. スプレッドシート上で、=GET_STOCK_PRICE("8058:TYO") 等として株価を取得。8058:TYO は Google Finance のティッカー

日本株の会社名を取得する関数の追加

関数名を GET_STOCK_NAME 等、数式の定義を、

=IMPORTXML("https://www.google.com/finance/quote/" & ticker & "?hl=ja","//*[@class=""zzDege""]")

として、日本株の株価を取得する関数の追加と同じ手順を実行。
=GET_STOCK_NAME("8058:TYO") 等で会社名が取得できる。

株価取得がブロックされた場合

  1. 他の株価が取得できるページを見つける
  2. ブラウザの Developer Tool で、株価の文字列で検索する (例 31,007)
  3. ChatGPT 等に株価の文字列の周囲のタブを渡して、株価の要素への XPath を作る
  4. IMPORTXML の 1 つ目の引き数を新しいページのURLに、2 つ目の引き数を 3 で作った XPath で置き換える

おまけ

  • USDJPY
    GET_STOCK_PRICE("USD-JPY")
    
  • オルカン
    =VALUE(IMPORTXML("https://finance.yahoo.co.jp/quote/0331418A","(//*[@class=""StyledNumber__value__3rXW""])[1]"))
    
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?