Check if item exists in selected url

I have a page with say 30 URLS, I need to click on each one and check if the item exists. This currently means:

$('area').each(function(){
    $(this).attr('target','_blank');
    var _href = $(this).attr("href"); 
    var appID = (window.location.href).split('?')[1];
    $(this).attr("href", _href + '?' + appID);
    $(this).trigger('click');
});

      

30 new tabs will open and I will manually go through them.

(all urls are in the same domain)

It would be nice to have a scanner with the following logic:

$('area').each(function(){

 1) get the HREF
 2) follow it
 3) on that new page:
    if($('.element')){
     push the $('area') into array1 
    } else {
     push the $('area') into array2
        }
    });


   4) Display array1 in green
      Display array2 in red

      

Basically, I'd like to create a report that says:

X scanned pages had a Y element

Z scanned pages has no Y element

I'm clearly stuck with generating Javascript / jQuery on a newly opened tab.

I found this one , this one and this one , but I'm not entirely sure if this is viable.

Can this be done with Javascript / jQuery?

I only ask for the right direction , I will take the steps myself.

Many thanks

+3


source to share


1 answer


I can suggest you use iframe

to load pages.

For example:

$.each($your-links, function(index, link) {
    var href = $(link).attr("href");
    // your link preprocess logic ...

    var $iframe = $("<iframe />").appendTo($("body"));
    $iframe.attr("src", href).on("load", function() {
        var $bodyContent = $iframe.contents().find("body");
        // check iframe content and remove iframe
        $iframe.remove();
    }
}

      



But, I must say, if your search and checked pages have different domains, there will be CORS problems .

I've created a simple project that shows how to implement this approach. You can download here and run on some local webserver (apache, iis, etc.)

+1


source







All Articles