1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- const webdriver = require('selenium-webdriver');
- const chrome = require('selenium-webdriver/chrome');
- const firefox = require('selenium-webdriver/firefox');
- const { saveFile } = require('./tools/save-file');
- const { baseData } = require('./tools/base-data');
- const { skuData } = require('./tools/sku-data');
- const { videoData } = require('./tools/video-data');
- const { imgsData } = require('./tools/imgs-data');
- const { downImg } = require('./tools/down-img');
- (async function example() {
- // let driver = await new Builder().forBrowser('chrome').build();
- let driver = new webdriver.Builder()
- .forBrowser('chrome')
- .build();
- driver.get('https://detail.tmall.com/item.htm?spm=a1z10.3-b-s.w4011-15438998729.159.167f3b511BHh5a&id=617256520600&rn=062ba2e2e6d139709e3e0e3505b56bbe&abbucket=3');
- // 检查登录
- await driver.wait(webdriver.until.elementLocated(webdriver.By.className('j_Username')), 100000, '超时未登录');
- console.log('登陆成功');
- driver.executeScript(function () {
- let y = 0;
- let timer = setInterval(() => {
- y += 50;
- if (y > 20000) {
- clearInterval(timer);
- }
- window.scrollTo(0, y)
- }, 10)
- })
- // 检查基本信息(判断详情加载完成)
- await driver.sleep(20000 / 50 * 10)
- 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) {
- }
- // // 延时一秒
- await driver.sleep(1000)
- let data = {};
- // 获取基础详情
- const bData = await baseData(driver);
- data = { ...bData };
- // imgs
- data.imgs = await imgsData(driver);
- // sku
- data.sku = await skuData(driver);
- console.log('开始保存')
- // video TODO: 视频用的blob暂不处理
- // data.video = await videoData(driver);
- saveFile(`test.html`, JSON.stringify(data, null, 4));
- downImg(data)
- })();
|