Stuck by "undefined error"

#1

Have a crawl running on a loop that extracts the link of an object.

Problem is there are occurrences on the page where where the object is not linked and its is producing “undefined errors” and effectively stopping the crawler.

$(this).find(’.Class’).attr( “href” )

how do I prevent this error and allow the loop to move on to the next selector?

I assume some If .Class equals or doesn’t equal but I’m stumped.

#2

Hello Kevin @Novarupta ,
basically you need to check whether there is the link that could have a href attribute, so you can use something like this

$('table#ember1342 tr').each(function(){
	if($(this).find('td.category a').length !== 0){
		console.log($(this).find('td.category a').attr("href"))
	}else{
                console.log("No link, keep on.")
        }
})

//results like:
///No link, keep on.
///c/crawlers
//No link, keep on.
//No link, keep on.
//No link, keep on.
//No link, keep on.

You can test it here on site in the console. If I find that element, I save the attribute href otherwise, I go to another element.

If you would have any kind of question, let me know.

Best regards,
Vasek