1

I want to download some images with PhantomJS but I have a little problem. My code is this:

page.open( url, function ( status ) {
    page.render( "test.jpg" );
    phantom.exit();
});

The problem is that the URL redirects to the home page of site. How can I disable the URL redirect and save the image? The URL is something like: http://some_url/00.jpg. I want to download this (and others) image from this site, but with the redirect is impossible for me save the image.

I have not found anything on the internet that might solve my problem. Anyone can help me?

G.F
  • 135
  • 10
  • Possible duplicate of [How to configure Poltergeist or PhantomJS to not follow redirects?](http://stackoverflow.com/questions/26809256/how-to-configure-poltergeist-or-phantomjs-to-not-follow-redirects) – Artjom B. Mar 13 '16 at 15:24
  • @ArtjomB.: I checked the article you suggested to me as a duplicate. I tried to implement that code but it does not solve my problem. The redirection remains the same. Seems that has no effect on this web site. – G.F Mar 13 '16 at 16:13
  • Have you included the URL that you don't want to be redirected to in the `redirectURLs` array? – Artjom B. Mar 13 '16 at 16:16
  • @ArtjomB.: Yes, but if I do this I get an error in page.open. If I add that page to redirectURLs array and I do page.render I get a black image. – G.F Mar 13 '16 at 20:22
  • The only way to prevent a redirect is to abort the redirect request. Only you know your source and target URLs, so play around with the snippet. – Artjom B. Mar 13 '16 at 20:42
  • @ArtjomB.: Then, do it is impossible. If I abort redirect URL request I get an error, if I don't do this I will be redirect. I'm going crazy. Initially I wanted to download images but I didn't find how could I do it with PhantomJS. I thought it was impossible to do, so I decided to open the images passing the URL to page.open and make a page.render to save them. With these problems is impossible save images. I tried to do this with PHP but I get same results. The redirection prevents me from saving images. – G.F Mar 13 '16 at 21:27
  • Mind the XY problem. So you're trying to download images of a page, but you're asking about stopping redirects instead. [Here](http://stackoverflow.com/a/25941115/1816580) is your answer. – Artjom B. Mar 13 '16 at 21:53
  • @ArtjomB.: Thank you so much. I thought I had no chance. I thought it was not possible to save images on PhantomJS. Thanks to the method that you have linked to me I was able to download the images. I had completely overlooked this hypothesis because I could not find anything over the Internet about it, so I just wanted to prevent redirection. – G.F Mar 14 '16 at 15:27

0 Answers0