[英]How to scrape Yahoo Finance with Cheerio in Javascript?
我正在嘗試根據舊帖子和 Yahoo Finance 中看到的最新價格屬性 (data-reactid="47") 從 Yahoo Finance 中獲取實時價格。 但以下代碼不會提取價格數據。 我錯過了什么? 我將不勝感激任何幫助。 謝謝!
function test() {
const url = 'https://finance.yahoo.com/quote/AAPL?p=AAPL&.tsrc=fin-srch';
const res = UrlFetchApp.fetch(url, { muteHttpExceptions: true }).getContentText();
const $ = Cheerio.load(res);
var price = $("span[data-reactid='47']").text().toString();
console.log(price)
}
我意識到它的標簽應該是 fin-streamer,而不是 span。 更改標簽名稱效果很好。
var price = $('fin-streamer[data-reactid="47"]').text().toString();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.