Node学习记录: 写脚本工具

发布时间:2019-06-19 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Node学习记录: 写脚本工具脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

简单的搜索脚本

安装 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()

Node学习记录: 写脚本工具

Node学习记录: 写脚本工具

自动登录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()

Node学习记录: 写脚本工具

nodejs论坛灌水小工具

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

一键上传七牛脚本

命令行批量截图

脚本宝典总结

以上是脚本宝典为你收集整理的Node学习记录: 写脚本工具全部内容,希望文章能够帮你解决Node学习记录: 写脚本工具所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: