I have got 1 minute interval, where i request a site. Averagely once per hour i got this error. Am i doing something wrong, or there is an issue in cheerio?
/home/pi/node_apps/project/node_modules/cheerio/lib/parse.js:69
var oldParent = node.parent || node.root,
TypeError: Cannot read property 'parent' of undefined
at Function.exports.update (/home/pi/node_apps/project/node_modules/cheerio/lib/parse.js:69:25)
at module.exports (/home/pi/node_apps/project/node_modules/cheerio/lib/parse.js:19:11)
at Function.exports.load (/home/pi/node_apps/project/node_modules/cheerio/lib/static.js:27:14)
at Request._callback (/home/pi/node_apps/project/app.js:56:19)
at self.callback (/home/pi/node_apps/project/node_modules/request/request.js:186:22)
at emitOne (events.js:77:13)
at Request.emit (events.js:169:7)
at Request.onRequestError (/home/pi/node_apps/project/node_modules/request/request.js:878:8)
at emitOne (events.js:77:13)
at ClientRequest.emit (events.js:169:7
Can you provide us some more code to help you solve this? Thanks
I'm also getting this error as well.
Sample code that causes the error.
for (var i = 0; max = rowsToCheckArray.length; i < max; i++) {
getTheDate(rowsToCheckArray[i].url, i, step);
}
function getTheDate(URL, iterator, step) {
request.get(URL, function(error, response, html) {
var $ = cheerio.load(html);
landingPageDate = $("div.content-wrapper div.layout--rev div.portable-one-whole:last-of-type ul.no-bullet li.zeta:last-of-type").text().trim();
setTheKeyValues("landingDate", landingPageDate, iterator, step, "Get the date on the landing page!");
});
}
+1
I have exactly the same problem, @carlylumel you solved this?
Hey folks: we'd be happy to help, but as noted in the "issue template" file, we really need some markup that demonstrates the failure in order to advise on this.
Hi @jugglinmike, sorry to have missed that! I can definitely add in some more info. I'm new to submitting issues to repos, what more in particular are you looking for?
@cmarrero01 I haven't solved this per se but have worked around it by returning the function I'm calling in a IIFE that's wrapped in setTimeout within the loop. Prevents the function from firing as quickly, which seems to prevent the error.
@carlylumel I have cheerio in a loop too. Thanks for your advice, I will check that. @jugglinmike sorry for the disorder, but is hard been wordy when I'm hurry.. I will take that in count next time.
Make sure you are not doing cheerio.load(undefined).
I realize i'm a little late to finding your thread but I was experiencing the same issue. In my case, there was an issue with the URL passed into request. I just had "www.ksl.com" and it needed to be "https://www.ksl.com/" including the https:// Just using the www.ksl.com resulted in HTML being undefined in cheerio.load(html). I thought I'd contribute in case someone else has the same issue and finds this thread like I did.
If URL is not a localhost. Check if you have internet connection or the website is up and running.
Typescript: Check the way you import Cheerio it may cause some issues.
Most helpful comment
A possible solution
Make sure you are not doing
cheerio.load(undefined).