I am having problems scraping a google search page. I can scrape a normal web page but the same code does not work on a search page
I am using nodejs with cheerio api. The search page is for the "restaurants near me". Here is the code
var request = require('request');
var cheerio = require('cheerio');
request('https://www.google.com/search?rlz=1C1CHBF_enUS795US795&q=restaurants+near+me&npsic=0&rflfq=1&rlha=0&rllag=43556429,-83953443,247&tbm=lcl&ved=2ahUKEwikkKDVhvPcAhUEmuAKHekOBl4QjGp6BAgDEE8&tbs=lrf:!2m1!1e2!2m1!1e5!2m1!1e1!2m1!1e3!3sIAE,lf:1,lf_ui:9&rldoc=1#rlfi=hd:;si:;mv:!1m3!1d37687.821017182374!2d-83.91493835!3d43.58986!2m3!1f0!2f0!3f0!3m2!1i324!2i313!4f13.1;tbs:lrf:!2m1!1e2!2m1!1e5!2m1!1e1!2m1!1e3!3sIAE,lf:1,lf_ui:9',(error,response,html)=>{
if(!error && response.statusCode==200){
const $= cheerio.load(html)
$(".dbg0pd").each(function(i, element){
var a = $(this);
console.log('This is from inside the loop')
console.log(a.text());
});
}
})
In the web page, running inspect element shows that the class dbg0pd
contains the div
element which contains the name of the restaurant. However the .each()
jquery loop does not even fire as my test console.log statement does not print This is from inside the loop
Running node scrape.js
does not print anything.