Skip to content

Instantly share code, notes, and snippets.

@nmaruy27
Created Sep 27, 2021
Embed
What would you like to do?
色んな数値取得用
function getOtherValue(stockCode, type) {
var code = String(stockCode).split(',')[0];
var url = 'https://irbank.net/';
var fromText = '';
var toText = '';
switch(type) {
case 'roe0':
fromText = 'ROE(連)</a></dt><dd><span class="ratio" style="width:16%;"></span><span class="text">';
toText = '</span>';
break;
case 'roe1':
fromText = 'ROE(連)<span class="co_gr">予</span></dt><dd><span class="exp" style="width:16%;"></span><span class="text">';
toText = '</span>';
break;
case 'eps0':
fromText = 'EPS(連)</a></dt><dd><span class="ratio" style="width:32%;"></span><span class="text">';
toText = '<span class="weaken">';
break;
case 'eps1':
fromText = 'EPS(連)<span class="co_gr">予</span></dt><dd><span class="exp" style="width:33%;"></span><span class="text">';
toText = '<span class="weaken">';
break;
default:
return '不正なタイプです。可能タイプ→ roe0/roe1/eps0/eps1'
}
var res = UrlFetchApp.fetch(url + code);
if(res.getResponseCode() == 200) {
var value = Parser.data(res.getContentText()).from(fromText).to(toText).build();
return value.trim().replace('%', '');
} else {
return '取得失敗';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment