我正在尝试从here导出div标签的“prod-details”我想知道是否有一种方法或脚本我可以在chrome dev工具中运行,这些工具会导出带有数据的CSV刮?
答案 0 :(得分:0)
我不会为你实现它;)但我认为这个工作流程可以帮助你完成任务。
document.querySelectorAll('.prod-details')
会让你开始。答案 1 :(得分:0)
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