サンプルプログラム

自動ダウンロード

データファイル自動ダウンロード用のサンプルプログラム・サンプルコマンドです。このサンプルでは「株価一覧表」の最新CSVファイル・JSONファイルをダウンロードしています。(最新ファイル:ファイル名にyyyymmdd形式の日付無し)

Python
id = "yourID"
pw = "yourPassword"

import urllib3
http = urllib3.PoolManager()

url = "https://csvex.com/kabu.plus/csv/japan-all-stock-prices/daily/japan-all-stock-prices.csv"
headers = urllib3.util.make_headers(basic_auth="%s:%s" % (id, pw) )
response = http.request("GET", url, headers=headers)
f = open("japan-all-stock-prices.csv", "wb")
f.write(response.data)
f.close()

url = "https://csvex.com/kabu.plus/json/japan-all-stock-prices/daily/japan-all-stock-prices.json"
headers = urllib3.util.make_headers(basic_auth="%s:%s" % (id, pw) )
response = http.request("GET", url, headers=headers)
f = open("japan-all-stock-prices.json", "wb")
f.write(response.data)
f.close()
C#
var uri = new Uri("https://csvex.com/kabu.plus/csv/japan-all-stock-prices/daily/japan-all-stock-prices.csv");
using (var webClient = new System.Net.WebClient())
{
	webClient.Credentials = new NetworkCredential("yourID", "yourPassword");
	webClient.DownloadFile(uri, @"C:\Temp\japan-all-stock-prices.csv");
}

var uri = new Uri("https://csvex.com/kabu.plus/json/japan-all-stock-prices/daily/japan-all-stock-prices.json");
using (var webClient = new System.Net.WebClient())
{
	webClient.Credentials = new NetworkCredential("yourID", "yourPassword");
	webClient.DownloadFile(uri, @"C:\Temp\japan-all-stock-prices.json");
}
Windows コマンドプロンプト curlコマンド
SET ID=yourID
SET PW=yourPassword

curl -u %ID%:%PW% -O "https://csvex.com/kabu.plus/csv/japan-all-stock-prices/daily/japan-all-stock-prices.csv"

curl -u %ID%:%PW% -O "https://csvex.com/kabu.plus/json/japan-all-stock-prices/daily/japan-all-stock-prices.json"
Mac ターミナル curlコマンド
ID="yourID"
PW="yourPassword"

curl -u $ID:$PW --compressed -O "https://csvex.com/kabu.plus/csv/japan-all-stock-prices/daily/japan-all-stock-prices.csv"

curl -u $ID:$PW --compressed -O "https://csvex.com/kabu.plus/json/japan-all-stock-prices/daily/japan-all-stock-prices.json"
Linux wgetコマンド
ID="yourID"
PW="yourPassword"

wget --http-user=$ID --http-passwd=$PW --header="Accept-Encoding:gzip" -O - "https://csvex.com/kabu.plus/csv/japan-all-stock-prices/daily/japan-all-stock-prices.csv" | gzip -cd > japan-all-stock-prices.csv

wget --http-user=$ID --http-passwd=$PW --header="Accept-Encoding:gzip" -O - "https://csvex.com/kabu.plus/json/japan-all-stock-prices/daily/japan-all-stock-prices.json" | gzip -cd > japan-all-stock-prices.json
参考 データファイルの文字コード・改行コード

CSVファイル : Shift-JIS・CRLF
JSONファイル : UTF-8・LF・BOM無し