Scrape image src URLs using PhantomJS
<p>I'm trying to get a list of all image src url's in a given webpage using PhantomJS.  My understanding is that this should be extremely easy, but for whatever reason, I can't seem to make it work.  Here is the code I currently have:  </p>

<pre><code>var page = require('webpage').create();
page.open('http://www.walmart.com');

page.onLoadFinished = function(){
    var images = page.evaluate(function(){
        return document.getElementsByTagName("img");
    });
    for(thing in a){
        console.log(thing.src);
    }
    phantom.exit();
}
</code></pre>

<p>I've also tried this:  </p>

<pre><code>var a = page.evaluate(function(){
    returnStuff = new Array;
    for(stuff in document.images){
        returnStuff.push(stuff);
    }
    return returnStuff;
});
</code></pre>

<p>And this:  </p>

<pre><code>var page = require('webpage').create();
page.open('http://www.walmart.com', function(status){
    var images = page.evaluate(function() {
        return document.images;
    });
    for(image in images){
        console.log(image.src);
    }
    phantom.exit();
});
</code></pre>

<p>I've also tried iterating through the images in the evaluate function and getting the .src property that way.<br>
None of them return anything meaningful. If I return the length of document.images, there are 54 images on the page, but trying to iterate through them provides nothing useful.  </p>

<p>Also, I've looked at the following other questions and wasn't able to use the information they provided: <a href="https://stackoverflow.com/questions/19063094/how-to-scrape-javascript-injected-image-src-and-alt-with-phantom-js">How to scrape javascript injected image src and alt with phantom.js</a> and <a href="https://stackoverflow.com/questions/16716753/how-to-download-images-from-a-site-with-phantomjs">How to download images from a site with phantomjs</a></p>

<p>Again, I just want the source url. I don't need the actual file itself.  Thanks for any help.</p>

<p><strong>UPDATE</strong><br>
I tried using </p>

<pre><code>var a = page.evaluate(function(){
    returnStuff = new Array;
    for(stuff in document.images){
        returnStuff.push(stuff.getAttribute('src'));
    }
    return returnStuff;
});
</code></pre>

<p>It threw an error saying that stuff.getAttribute('src') returns undefined. Any idea why that would be?</p>