我正在尝试从网页https://www.barchart.com/stocks/quotes/aapl/performance上的价格表现表中抓取所有行, 它是折线图下方的表格。该表没有任何 id 或 class 属性。我试图从它包含的 div 中获取表格。下面是代码,但它没有打印 td 元素内的文本。
$ = await fetchData(performanceHistoryUrl);
let performanceTableDiv = $(".bc-table-scrollable-inner") // Class of div which is enclosing table
var childSelector = 'table' // table selector
var performanceTable = performanceTableDiv.find(childSelector)
performanceTable.each((index, element) => {
if (index === 0) return true;
const tds = $(element).find("td");
const colOne = $(tds[0]).text();
const colTwo = $(tds[1]).text();
const colThree = $(tds[2]).text();
const tableRow = { colOne, colTwo, tableRow };
console.log(tableRow);
});
Run Code Online (Sandbox Code Playgroud)