1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- // 保存文件
- const fs = require('fs');
- const path = require('path');
- const webdriver = require('selenium-webdriver');
- const { saveFile } = require('../tools/save-file');
- const { baseData } = require('../tools/base-data');
- const { skuData } = require('../tools/sku-data');
- const { downImg } = require('./down-img');
- function pageInit(driver) {
- return new Promise((resolve, reject) => {
- driver.executeScript(function () {
- let y = 0;
- let timer = setInterval(() => {
- y += 50;
- if (y > 20000) {
- clearInterval(timer);
- }
- window.scrollTo(0, y)
- }, 10)
- })
- // 检查基本信息(判断详情加载完成)
- driver.sleep(20000 / 50 * 10 + 1000).then(async () => {
- console.log('自动滚动完成');
- // 判断是否有验证框
- try {
- const dialog = await driver.findElement(webdriver.By.className('baxia-dialog'));
- if (dialog) {
- const ele = await driver.findElement(webdriver.By.js(() => document.querySelector('.baxia-dialog .baxia-dialog-close')))
- ele.click();
- }
- console.log('有验证框');
- } catch (error) {
- }
- let data = {};
- // 获取基础详情
- baseData(driver).then(bData => {
- data = { ...bData };
- console.log('基础数据获取完成')
- skuData(driver).then(sku => {
- data.sku = sku;
- console.log('sku获取完成')
- saveFile(`/json/${data.title}.json`, JSON.stringify(data, null, 4));
- downImg(data);
-
- const random = parseInt(Math.random() * 6 + 3) * 1000;
- setTimeout(() => {
- console.log('完成一个');
- resolve();
- }, random)
- })
- });
- })
- });
- }
- exports.pageInit = pageInit;
|