1.0.12 • Published 4 years ago

nightmare-handler v1.0.12

Weekly downloads
19
License
MIT
Repository
github
Last release
4 years ago

nightmare-handler

nightmare 基础上做了扩展,保持了其原始的功能,并提供一些工具。

安装

$ npm install nightmare-handler

使用

const nightmareHandler = require('nightmare-handler');

// 获得扩展之后的 Nightmare
const NightmarePlus = nightmareHandler.getNightmarePlus();

// 初始化 nightmare 对象
const nightmare = NightmarePlus({ show: true });

// 执行
nightmare
    .exDevice('mobile')
    .goto('http://www.baidu.com')
    .wait('#index-bn')
    .evaluate(function () {
        return {
            title: document.title,
            searchBtnTxt: document.querySelector('#index-bn').innerText,
            width: window.innerWidth,
            height: window.innerHeight,
            userAgent: navigator.userAgent
        };
    })
    .end()
    .then(function (result) {
        console.log('success: ', result);
    })
    .catch(function (error) {
        console.error('error: ', error);
    });

方法

Nightmare 和 getNightmarePlus(config)

import { Nightmare, getNightmarePlus } from 'nightmare-handler';

Nightmare 就是 nightmare ,而 getNightmarePlus(config) 方法返回的对象是对 Nightmare 进行了扩展(Extending Nightmare )等处理。

getNightmarePlus(config) 参数说明:

  • config.deviceMap,设备配置,格式为 { name : { UA, width, height } }

已扩展的方法列表如下:

如果上述提供的扩展方法不满足您的诉求,可以选择 自定义扩展 NightmarePlus.extend(callExtend, opts)

事件相关

nightmare 加载页面时,会产生一系列事件,具体请查看 关于页面的事件

调试模式

使用 DEBUG=nightmare* node xxx.js 方式,可以打印出 nightmare 的诸多日志。

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.2.1

6 years ago

0.2.0

6 years ago

0.1.0

6 years ago