【发布时间】:2020-06-26 01:32:27
【问题描述】:
(async () => {
const browser = await puppeteer.launch({headless:false})
const page = await browser.newPage()
await page.goto("https://www.nguyenkim.com/tv-qled-samsung-65-inch-qa65q65rakxxv.html")
const model = await page.evaluate(() => {
let location = document.querySelectorAll(".bg-Pro")
let name = document.querySelector(".product_info_name")
let price = document.querySelector(".nk-price-final")
let gift = document.querySelector(".cm-picker-product-options div:first-child")
let gift2 = document.querySelector(".cm-picker-product-options div:nth-child(2)")
let gift3 = document.querySelector(".cm-picker-product-options div:nth-child(3)")
let gift4 = document.querySelector(".cm-picker-product-options div:nth-child(4)")
let gift5 = document.querySelector(".cm-picker-product-options div:nth-child(5)")
let gift6 = document.querySelector(".cm-picker-product-options div:nth-child(6)")
let gift7 = document.querySelector(".cm-picker-product-options div:nth-child(7)")
let infor = []
location.forEach((item) => {
infor.push({
Name: name.innerText,
Price: price.innerText,
Gift: gift.innerText,
Gift2: gift2.innerText,
Gift3: gift3.innerText,
Gift4: gift4.innerText,
Gift5: gift5.innerText,
Gift6: gift6.innerText,
Gift7: gift7.innerText
});
});
return infor;
});
console.log(model);
嗨,伙计,我需要一些帮助! 我做了一个项目,但我不知道如何导出excel??有人知道怎么出口吗?? 我做了研究,但我仍然没有在 google 中找到任何有用的东西。我希望我能在这里找到它:D p/s:我的英语不是我的母语。谢谢你的时间!!
const puppeteer = require('puppeteer');
const fs = require('fs');
var csvWriter = require('csv-write-stream');
var writer = csvWriter({sendHeaders: false});
var xuat = "xuat.csv";
(async () => {
const browser = await puppeteer.launch({headless:false})
const page = await browser.newPage()
await page.goto("https://www.nguyenkim.com/tv-qled-samsung-65-inch-qa65q65rakxxv.html")
const model = await page.evaluate(() => {
let location = document.querySelectorAll(".bg-Pro")
let name = document.querySelector(".product_info_name")
let price = document.querySelector(".nk-price-final")
let gift = document.querySelector(".cm-picker-product-options div:first-child")
let gift2 = document.querySelector(".cm-picker-product-options div:nth-child(2)")
let gift3 = document.querySelector(".cm-picker-product-options div:nth-child(3)")
let gift4 = document.querySelector(".cm-picker-product-options div:nth-child(4)")
let gift5 = document.querySelector(".cm-picker-product-options div:nth-child(5)")
let gift6 = document.querySelector(".cm-picker-product-options div:nth-child(6)")
let gift7 = document.querySelector(".cm-picker-product-options div:nth-child(7)")
let infor = []
location.forEach((item) => {
infor.push({
Name: name.innerText,
Price: price.innerText,
Gift: gift.innerText,
Gift2: gift2.innerText,
Gift3: gift3.innerText,
Gift4: gift4.innerText,
Gift5: gift5.innerText,
Gift6: gift6.innerText,
Gift7: gift7.innerText
});
});
return infor;
});
console.log(model);
await browser.close();
})();
嗨,伙计,我需要一些帮助! 我做了一个项目,但我不知道如何导出excel??有人知道怎么出口吗?? 我做了研究,但我仍然没有在 google 中找到任何有用的东西。我希望我能在这里找到它:D p/s:我的英语不是我的母语。谢谢你的时间!!
【问题讨论】:
-
嗨,你想把
model导出到excel文件吗? -
是的,兄弟.. 我不知道如何导出这个“const 模型”
标签: node.js web-crawler