我正在尝试从 here 导出 div 标签“prod-details”我想知道是否有一种方法或脚本可以在 chrome 开发工具中运行来导出 CSV 并抓取数据?
最佳答案
Kayce 不为您执行此操作可能是正确的,但是开始可能会很困难,因此这里有一个基本的实现,其中包含您可以使用的注释。请务必阅读并尝试理解它,而不仅仅是复制和粘贴它。
// Create a list of the selectors within each prod-deatils you'd like to export as a column
var columnSelectors = [".brand", ".model", ".finish", ".ProductPriceDetails"];
// Create an array with the column selectors at the top to act as a header
[columnSelectors.join(",")].concat(
// Grab the product details and arrayify it so we can use standard array functions
$(".prod-details").toArray()
// These are elements, and we want to be able to use jquery with them, so wrap each element with jquery
.map(d => $(d))
// For each prod-detail element, we want to extract each of the columns
.map(d =>
columnSelectors.map(
// ... so we iterate the selectors and apply each one to the product, grab the text and trim() it to remove whitespace
sel => d.find(sel).text().trim()
).join(",") // Finally join each of the columns with a comma so it follows CSV format
)
).join("\n"); // And join all the rows with newlines
关于javascript - 如何从嵌套 div 标签中抓取数据并从开发工具导出到 CSV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40934474/