web scriping in javascript
npm init -y type this in terminal
npm install request
npm js request
it should contain a function with a request URL and one callback function
with the help of cheerio we can manipulate the data
const request = ;;/////////////////////////// const request = require('request');// const requre = require("cheerio");// const fs = require("fs");// request("https://www.espncricinfo.com/series/ipl-2021-1249214/punjab-kings-vs-delhi-capitals-29th-match-1254086/ball-by-ball-commentary",callback);// //// function callback(error, response, html) {// if(!error){// const manipulationTool = cheerio.load(html);// let comments = manipulationTool("match-comment-long-text p");// // console.log(comments);// let reqComment = manipulationTool(comments[0].text());// console.log(reqComment);// // fs.writeFileSync("google.html",html);// // console.log('body:', body); // Print the HTML for the Google homepage.// }// }// //null is a false state and !null is trueconst request = require("request");const cheerio = require("cheerio");request("https://www.espncricinfo.com/series/ipl-2021-1249214/punjab-kings-vs-delhi-capitals-29th-match-1254086/ball-by-ball-commentary",callback);function callback(error, response, html) {if (!error) {const manipulationTool = cheerio.load(html);let comments = manipulationTool(".col-14.col-md-15.col-lg-14 .match-comment-long-text p");let reqComment = manipulationTool(comments[0]).text();console.log(reqComment);}}const request = require("request");const cheerio = require("cheerio");const { text } = require("cheerio/lib/static");request("https://www.espncricinfo.com/series/ipl-2021-1249214/punjab-kings-vs-delhi-capitals-29th-match-1254086/full-scorecard",callback);function callback(error, response, html) {if (!error) {const manipulationTool = cheerio.load(html);let bothTable = manipulationTool(".table.bowler");let player = "";let maxwicket = 0;for(let i = 0;i<bothTable.length;i++){let tablerow = manipulationTool(bothTable[i]).find("tbody tr");for(let j = 0;j<tablerow.length;j++){let allRowColumns = manipulationTool(tablerow[j]).find("td");let currplayername = manipulationTool(allRowColumns[0]).text();let currplayerwicket = manipulationTool(allRowColumns[4]).text();if(maxwicket<currplayerwicket){maxwicket = currplayerwicket;player = currplayername;}}}console.log(player);}}
Comments
Post a Comment