当前位置:网站首页>Node crawls LOL hero information
Node crawls LOL hero information
2022-08-07 19:22:00 【Deduct 1 to send Hellfire】
Connect to mongodb database and insert multiple data
function insertMany(collection,arr){return new Promise((resolve,reject)=>{var MongoClient = require('mongodb').MongoClient;var url = 'mongodb://127.0.0.1:27017/';MongoClient.connect(url, function(err, db){if(err) {throw err}var dbo = db.db('lolinfo');//Connect to the lolinfo databasedbo.collection(collection).insertMany(arr,function(err,res){if(err) reject(err);console.log("The document input is successful, the number of inserted documents is ",res.insertedCount);db.close();resolve();})})})}Get list of heroes
Enter the official website f12 to get the interface

//Get the list of heroesasync function getHeroList(){let httpUrl = 'https://game.gtimg.cn/images/lol/act/img/js/heroList/hero_list.js';let res = await axios.get(httpUrl);console.log(res.data.hero);await insertMany('herolist',res.data.hero);return res.data.hero;}getHeroList()
Get single hero information through heroID

Connect to the mongodb database and insert a hero information
function insertOne(collection,obj){return new Promise((resolve,reject)=>{const MongoClient = require('mongodb').MongoClientconst url = 'mongodb://127.0.0.1:27017/'MongoClient.connect(url, function(err, db){if(err) {throw err}var dbo = db.db('my');//Connect to the lolinfo databasedbo.collection(collection).insertOne(obj,function(err,res){if(err) reject(err)console.log("Document input successfully");db.close();resolve()})})})}Insert data
async function getHero(heroid){let httpUrl = `https://game.gtimg.cn/images/lol/act/img/js/hero/${heroid}.js`let result = await axios.get(httpUrl)await insertOne('heroInfo', result.data.hero)// console.log(result.data.hero);return result.data}async function run(){let herolist = await getHeroList()// console.log(herolist);await herolist.reduce(async (pre,item,index)=>{await prereturn new Promise(async(resolve,reject)=>{await getHero(item.heroId)resolve()})}, Promise.resolve())}run()
边栏推荐
- English Convert - Online English Batch Converter Free
- [chestnut sugar GIS] DOS - how to create subfolders in batches inside the current folder
- 数据库小记
- 约数及约数个数,约数乘积的计算
- Make a bouncing ball game in 5 minutes
- canvas实现图片标记
- Haochen Software IPO meeting: annual revenue of 240 million to raise 750 million Sequoia is a shareholder
- [2022 Hangdian Multi-School 5] Count Set (generating function divide and conquer NTT)
- 在vscode里打开IntelliSense配置的方法
- 浩辰软件IPO过会:年营收2.4亿拟募资7.5亿 红杉是股东
猜你喜欢
随机推荐
Chapter 61 Jquery JSON Table EntityFrameworkCore automatic generation of database
Laravel 使用QQ邮箱发送邮件
第61章 Jquery JSON Table EntityFrameworkCore自动生成数据库
基于 Next.js实现在线Excel
浩辰软件IPO过会:年营收2.4亿拟募资7.5亿 红杉是股东
约数及约数个数,约数乘积的计算
word翻译-批量word翻译
Shell编程之正则表达式
English Convert - Online English Batch Converter Free
SQL Server 递归+向上统计
架构实战文档全套集齐了
使用NTS理解细粒度图像分类
Make a bouncing ball game in 5 minutes
Kuaishou management adjustment: Liu Feng and Ma Hongbin are respectively in charge of commercialization and internationalization
Scala entry to proficient (Shang Silicon Valley study notes)
636. Exclusive time of functions: Simple stack application simulation problem
翻译软件哪个准确度高
函数简介篇——container_of 宏的理解
从0到1理解c函数
职场经验分享--接口中按时间戳查数据容易被忽略的细节








![[chestnut sugar GIS] DOS - how to extract the folder name](/img/c9/3e37571faf98fad6012152c9ffc5bd.png)
