简单的搜索脚本

安装 nightmare
安装 babel-register
安装 babel-polyfill

const Nightmare = require('nightmare');
const nightmare = Nightmare({ show: true });

const run = async () => {
  nightmare.goto('http://www.baidu.com')
}

这里的goto是异步执行的,会返回一个promise
前面加个await 使它以同步的方式执行

index.js

require('babel-register');
require('babel-polyfill');
require('./run')

run.js



const Nightmare = require('nightmare');
const nightmare = Nightmare({ show: true });

const run = async () => {
  await nightmare.goto('http://www.baidu.com')
  await nightmare.type('#kw','海贼王')
  await nightmare.click("#su")
}


run()

图片描述

图片描述

自动登录cnode论坛

新建一个config.js文件


export default {
  username: "AlexZ33",
  password: "自己的密码"

}

run.js变成


const Nightmare = require('nightmare');
const nightmare = Nightmare({ show: true });
import config from './config.js'

const run = async () => {
  await login()
}




const login = async () =>{
  await nightmare.goto('https://cnodejs.org/signin')
  await nightmare.wait('#signin_form')

  await nightmare.click('.form-actions :nth-child(2)')
  await nightmare.wait('#login_field')

  await nightmare.type('#login_field', config.username)
  await nightmare.type('#password',config.password)

  await nightmare.click('input[name="commit"]')
}

run()

图片描述

nodejs论坛灌水小工具

nodejs链接linux,并上传代码进行半自动化更新

一键上传七牛脚本

命令行批量截图


白鲸鱼
1k 声望110 粉丝

方寸湛蓝