1. https://github.com/ariya/phantomjs 2. https://github.com/laurentj/slimerjs 3. https://github.com/casperjs/casperjs 4. https://github.com/segmentio/nightmare
这里主要用了nightmare这个库 感兴趣的同窗能够自行去github 上了解这个库 git
==nightmare==:目标是暴露模拟用户动做(如几个简单的方法goto,type和click),其中,感受同步的脚本中的每一个块,而不是深度嵌套的回调的API。它最初设计用于在没有API的站点之间自动执行任务,但最经常使用于UI测试和爬网github
npm install -y //创建一个package.json的文件 npm install --save nightmare //安装依赖库
import Nightmare from 'nightmare'; const nightmare = Nightmare({ show: true }); nightmare .goto('https://duckduckgo.com') .type('#search_form_input_homepage', 'github nightmare') .click('#search_button_homepage') .wait('#r1-0 a.result__a') .end() .then(console.log) .catch((error) => { console.error('Search failed:', error); });
.wait(()=>{})当中也能够放置函数(例如能够判断目标文件是否存在的函数)npm
nightmare .goto(someUrl) .end(() => "some value") //打印 "some value" .then(console.log);
这是我作的一个翻译的小程序 json