Monday 15 March 2010

CasperJs Check if File is Downloaded/ Javascript Check if File Exists Locally -


Question: How to check with the case or javascript (later) if my file was downloaded Is successful?

I crawl some blogs and download images, unfortunately, it does not always download the image.

The caspar script is run locally from my computer. I save all the files I downloaded (or failed to download) in a JSN function, if it does not give any information to itself It succeeds:

Unexpected reach 1:

  function UrlExists (url) {var http = New XMLHttpRequest (); Http.open ('HEAD', url, false); Http.send (); Return http.status! = 404; }  

But I think it only works on a server, it throws an error:

NETWORK_ERR: XMLHttpRequest exception 101: a network Error occurred in synchronous requests.

Failure access 2:

I also got the following approach, which does not work in casper Or at least it does not display anything.

  function check image (src) {console.log ("check"); Var img = new image (); Img.onload = function () {console.log ("yes");}; Img.onerror = function () {console.log ("no");}; Img. Src = src; }           / P> 
  Function ImageExist (url) {var img = new Image (); Img.src = '/ user / master_gallery/project/paleo-crawler /' + site + '/' + url; Console.log (img.src, "-", img.height); Return img.height! = 0; }  


No comments:

Post a Comment