【发布时间】:2021-09-08 20:52:23
【问题描述】:
我正在尝试从网页 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);
});
【问题讨论】:
标签: node.js web-scraping cheerio