什么是npm包?
npm (Node.js Package Manager) 是 Node.js 代码包(moudles)的管理工具。npm包就是在这个工具上发布的模块,它可以用来组成脚本,拓展其功能,提高开发效率和规范性。npm包可以在Node.js运行环境中,快速下载、安装和管理。
node-red-contrib-retrieve-rank-full-response是什么?
node-red-contrib-retrieve-rank-full-response是一个npm包,它是使用node-red平台进行开发的,用于获取搜索引擎的排名和完整的响应数据,支持百度、搜狗和360搜索引擎。
如何使用node-red-contrib-retrieve-rank-full-response?
安装
在线安装:
npm i node-red-contrib-retrieve-rank-full-response
手动安装:
在终端中切换到Node-red的用户目录,执行以下命令:
cd ~/.node-red && npm i node-red-contrib-retrieve-rank-full-response
功能
在节点页面中输入查询字符串,选择搜索引擎和页面数,即可获取相应的搜索排名和完整响应数据。
示例代码
先在Node-red中安装node-red-contrib-retrieve-rank-full-response,并启动。然后新建一个node-red流程,在此流程中选择一个function节点。在该function节点中使用以下代码:
-- -------------------- ---- ------- --- ----- - ----------------------------------------------- --- ------ - -------- --- ----- - -- ----------- - - ------ ------ ------- ------- ------ ----- -- ------ ----
在function节点中设置一个msg.payload的Javascript对象,其中包含所需的查询字符串,搜索引擎和查询页面数。
接下来,在该流程的末尾部分选择retrieve-rank-full-response节点,使用以下Javascript代码:
-- -------------------- ---- ------- -- -------- ------ ---- --- ---- -------- --- ---- ------ ------ --- -------- - ------------------- --- ------------ - ------------------- --- ---- - -- ------- ---- - - ---------------- ----- ----------- ------- ------------ -------------------------- -- - ----------- - ---- ------ ---
通过这些代码,您可以获得完整的搜索结果响应列表和排名。除此之外,还可以访问其他搜索引擎和定义其他页数。
此外,您可以在Node-red的“编辑器”页面中找到更多有关如何使用node-red-contrib-retrieve-rank-full-response的文档和示例。
使用该npm包的例子请参见:
[{"id":"e4191781.4019c","type":"function","z":"5edeca09.df7e0c","name":"Configure Search","func":"let query = \"node-red-contrib-retrieve-rank-full-response\";\nlet engine = \"baidu\";\nlet pages = 1;\n\nmsg.payload = {\n query: query,\n engine: engine,\n pages: pages\n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":180,"y":240,"wires":[["142a259f.3ab3e3"]]},{"id":"6bcf83e0.92b4d4","type":"debug","z":"5edeca09.df7e0c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":320,"wires":[]},{"id":"142a259f.3ab3e3","type":"retrieve-rank-full-response","z":"5edeca09.df7e0c","name":"","dir":"","x":420,"y":240,"wires":[["6bcf83e0.92b4d4"]]},{"id":"fec859c7.7a97b","type":"inject","z":"5edeca09.df7e0c","name":"run","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":100,"y":320,"wires":[["e4191781.4019c"]]}]
以上就是有关如何使用node-red-contrib-retrieve-rank-full-response的详细介绍,如果您有需要,可以到Node-red Package页面进一步了解其他npm包。
来源:JavaScript中文网 ,转载请注明来源 https://www.javascriptcn.com/post/60055ead81e8991b448dc29a