试图让 'Growth Rate' 变成 google sheet
trying to get 'Growth Rate' to google sheet
对于以下示例,我尝试获取索引 C1 中票证的增长率:
=IMPORTXML(concatenate("https://www.gurufocus.com/term/dividend_growth_5y/",index(C1),"/5-Year-Dividend-Growth-Rate/")," //*[@id="target_def_description"]/p[2]/strong[9]")
请指教
10倍
Y.
当我使用您的 URL 测试您的公式时,出现 Could not fetch url
错误。因此,在这个答案中,作为一种解决方法,我想建议使用 Google Apps 脚本来实现您的目标。
示例脚本:
请将以下脚本复制粘贴到Spreadsheet的脚本编辑器中,在单元格中放入自定义公式=SAMPLE(url)
。这样,脚本就是运行.
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
if (res.getResponseCode() != 200) throw new Error(res.getContentText());
const meta = res.getContentText().match(/<meta name\="description"[\s\S\w]+?>/);
if (meta) {
const gr = meta[0].match(/ ([0-9.]+%)/);
if (gr && gr.length == 2) {
return gr[1];
}
}
return "Value cannot be retrieved.";
}
结果:
当https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate/ATT-Inc#:%7E:text=AT%26T%27s%20Dividends%20per%20Share%20for,Rate%20was%201.80%25%20per%20year
和https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate
的URL上面的脚本是运行时,得到下面的结果。
注:
- 此示例脚本可用于
https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate/ATT-Inc#:%7E:text=AT%26T%27s%20Dividends%20per%20Share%20for,Rate%20was%201.80%25%20per%20year
和 https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate
的 URL。因此,当您更改 URL 时,脚本可能无法使用。所以请注意这一点。
参考文献:
对于以下示例,我尝试获取索引 C1 中票证的增长率:
=IMPORTXML(concatenate("https://www.gurufocus.com/term/dividend_growth_5y/",index(C1),"/5-Year-Dividend-Growth-Rate/")," //*[@id="target_def_description"]/p[2]/strong[9]")
请指教 10倍 Y.
当我使用您的 URL 测试您的公式时,出现 Could not fetch url
错误。因此,在这个答案中,作为一种解决方法,我想建议使用 Google Apps 脚本来实现您的目标。
示例脚本:
请将以下脚本复制粘贴到Spreadsheet的脚本编辑器中,在单元格中放入自定义公式=SAMPLE(url)
。这样,脚本就是运行.
function SAMPLE(url) {
const res = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
if (res.getResponseCode() != 200) throw new Error(res.getContentText());
const meta = res.getContentText().match(/<meta name\="description"[\s\S\w]+?>/);
if (meta) {
const gr = meta[0].match(/ ([0-9.]+%)/);
if (gr && gr.length == 2) {
return gr[1];
}
}
return "Value cannot be retrieved.";
}
结果:
当https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate/ATT-Inc#:%7E:text=AT%26T%27s%20Dividends%20per%20Share%20for,Rate%20was%201.80%25%20per%20year
和https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate
的URL上面的脚本是运行时,得到下面的结果。
注:
- 此示例脚本可用于
https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate/ATT-Inc#:%7E:text=AT%26T%27s%20Dividends%20per%20Share%20for,Rate%20was%201.80%25%20per%20year
和https://www.gurufocus.com/term/dividend_growth_5y/T/5-Year-Dividend-Growth-Rate
的 URL。因此,当您更改 URL 时,脚本可能无法使用。所以请注意这一点。