I am trying to manipulate a string by splitting it into two.
my js
var request = require('request');
var cheerio = require('cheerio');
var href1,href;
var str = "https://google.co.in/search?q=okay"+"+google";
request(str, function (error, response, html) {
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var a = $('.r a');
href = a.attr('href');
href1="https://google.co.in"+href;
var href
console.log(href1);
request(href1, function (error, response, html){
if (!error && response.statusCode == 200) {
var $ = cheerio.load(html);
var a1 = $('ol li a');
var href2 = a1.attr('href');
var href3 = href2.indexOf("/48");
var href4=href3.substring(0,20);
console.log(href4);
}
});
}
});
it gives a TypeError at the line where i use the substring function :
Undefined is not a function.
However, href3 returns an integer and that is fine. So, I know href3 is not empty or undefined.
How can I fix ?