当前位置: 首页 > 后端技术 > Node.js

智能浏览器软件

时间:2023-04-03 11:09:59 Node.js

SoftwareSmartLife介绍了几个有用的库(GitHub地址)。如果您想了解更多,可以自己查看。1.https://github.com/ariya/phantomjs2。https://github.com/laurentj/slimerjs3。https://github.com/casperjs/casperjs4。https://github.com/segmentio/nightmare这个库主要用到这里。有兴趣的同学可以去github自己了解一下这个库==nightmare==:目标是暴露模拟用户的动作(比如几个简单的方法goto,type,click),每块脚本感觉是同步的,而不是深度嵌套的回调API。它最初设计用于在没有API的情况下自动执行站点之间的任务,但最常用于UI测试和爬虫Installpluginsnpminstall-y//构建一个package.json文件npminstall--savenightmare//安装依赖简单介绍到图书馆插件参考。这是文件的概要。您可以根据自己的需要进行更改。从“噩梦”导入噩梦;constnightmare=Nightmare({show:true});nightmare.goto('https://duckduckgo.com').type('#search_form_input_homepage','githubnightmare').click('#search_button_homepage').wait('#r1-0a.result__a').end().then(console.log).catch((error)=>{console.error('搜索失败:',error);});.goto链接的urltypego模拟搜索文本框添加要查找的文本框,添加需要的文本click模拟鼠标点击事件方法同上wait检查多长时间在.wait()条件成功之间等待。Wait(()=>{})也可以放置函数(比如可以判断目标文件是否存在的函数)。end()结束文件你也可以使用nightmarewithpracticalthen.goto(someUrl).end(()=>"somevalue")//print"somevalue".then(console.log);这是我做的一个小翻译程序