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