const cheerio = require('cheerio'); var entities = require('html-entities').XmlEntities; const webdriver = require('selenium-webdriver'); function imgsData(driver) { return new Promise(async (resolve, reject) => { let imgList = await driver.findElements(webdriver.By.js(() => document.querySelectorAll('#J_UlThumb li'))) let imgs = []; let imgIndex = 0; async function eachImg(imgIndex) { const img = imgList[imgIndex]; // 创建鼠标 const actions = driver.actions({ async: true }); await actions.move({ origin: img }).perform(); await driver.sleep(1000); let obj = {}; const thumbnailEle = await img.findElement(webdriver.By.tagName('img')); obj.thumbnail = await thumbnailEle.getAttribute('src'); const imgEle = await driver.findElement(webdriver.By.js(() => document.querySelector('#J_ImgBooth'))) obj.img = await imgEle.getAttribute('src'); imgs.push(obj); imgIndex++; if (imgIndex === imgList.length) { resolve(imgs); } else { eachImg(imgIndex); } } eachImg(imgIndex); }); } exports.imgsData = imgsData;