ariya / phantomjs

Scriptable Headless Browser
http://phantomjs.org
BSD 3-Clause "New" or "Revised" License
29.47k stars 5.75k forks source link

File download #10052

Closed ariya closed 4 years ago

ariya commented 13 years ago

alexsa...@gmail.com commented:

It would be good to accept (and save) 'Content-Disposition: attachment; filename=' content.

Disclaimer: This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #52. :star2:   40 people had starred this issue at the time of migration.

sgraham commented 9 years ago

I rebased @Vitallium s download-support on 2.0 here https://github.com/sgraham/phantomjs/tree/download-support-vs-2.0 in case anyone else wants it to save the bother of doing the merge/apply.

I followed the Linux build instructions here http://phantomjs.org/build.html and this simple example works OK. Would be great to have something in mainline!

var page = require('webpage').create();

page.onResourceReceived = function(status) {
  console.log('onResourceReceived(' + status.contentType + ')');
  if(status.stage === 'end') {
    phantom.exit(0);
  }
}

page.onResourceRequested = function(requestData, networkRequest) {
  console.log('onResourceRequested(' + JSON.stringify(requestData) + ')');
}

page.onFileDownload = function(status) {
  console.log('done');
  return 'sample.pdf';
}

page.open('http://www.cbu.edu.zm/downloads/pdf-sample.pdf');
kwouters commented 8 years ago

I compiled sgraham's branch above, but there seems to be a difference with the windows build by ankitgr8 (https://github.com/ankitgr8/phantomjs2.0). The build of sgraham's branch does not trigger onFileDownload in my case (zipfile download). So for the moment, I'm running ankitgr8's thing with wine. ( yes, I know -- newbie).

(masked) output of onResourceReceived:

Received { "body": "", "bodySize": 0, "contentType": "application/zip;charset=UTF-8", "headers": [ { "name": "Date", "value": "Thu, 14 Jan 2016 xx:xx:xx GMT" }, { "name": "Content-Disposition", "value": "attachment; filename=somefilename.zip" }, { "name": "Expires", "value": "0" }, { "name": "Cache-Control", "value": "must-revalidate, post-check=0, pre-check=0" }, { "name": "Pragma", "value": "public" }, { "name": "Keep-Alive", "value": "timeout=10, max=100" }, { "name": "Connection", "value": "Keep-Alive" }, { "name": "Transfer-Encoding", "value": "chunked" }, { "name": "Content-Type", "value": "application/zip;charset=UTF-8" } ], "id": XX, "redirectURL": null, "stage": "end", "status": 200, "statusText": "OK", "time": "2016-xx-xxTxx:xx:xx.xxxZ", "url": "https://domain/dir" }

lanzorg commented 8 years ago

Does downloading large files with PhantomJS 2.1 work?

lanzorg commented 8 years ago

How? How to download this quite big file from phamtomjs for example? https://download.jetbrains.com/idea/ideaIC-15.0.3.tar.gz

vitallium commented 8 years ago

@lanzorg no, you can't download files with PhantomJS.

ankitgr8 commented 8 years ago

Did u tried my private build it is on windows https://github.com/ankitgr8/phantomjs2.0

I have also attached the sample code for the same

ser10us commented 8 years ago

Any chance it will be available in the next release?

fpemud commented 8 years ago

+1. File downloading would be a great feature for PhantomJS.

Schweinepriester commented 8 years ago

+1

gabrbuiv commented 8 years ago

+1

lycovian commented 8 years ago

+1. Just wasted a couple of days converting my Selenium Firefox script that downloads a CSV to use PhantomJS only to find this ticket. Very sad now.

v-pravin commented 8 years ago

+1

bschwagg commented 8 years ago

+1

Staf4 commented 8 years ago

+1 очень нужна возможность скачивания файлов

bedantaguru commented 8 years ago

+1

Thanking you Indranil Gayen

On Mon, Apr 4, 2016 at 8:52 PM, Staf4 notifications@github.com wrote:

+1 очень нужна возможность скачивания файлов

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/ariya/phantomjs/issues/10052#issuecomment-205346505

ekimeel commented 8 years ago

+1

mentero commented 8 years ago

This is awesome. I am watching this issue for 2 years now and it amazes me how people keep bumping it :)

paos commented 8 years ago

+1

patrick7kelly commented 8 years ago

+1

geotheory commented 8 years ago

+Googolplex

dronezzzko commented 8 years ago

5 years have passed!

Alexhha commented 8 years ago

It would be a really useful to implement download feature.

KhArtNJava commented 8 years ago

Yeah, why no download feature? ((( I want download files with phantomjs

dronezzzko commented 8 years ago

I think the author is a liar and he never planned to release this feature.

LinusU commented 8 years ago

I think the author is a liar and he never planned to release this feature.

Hey, the author is doing this on his spare time and is giving away all of it for free. Things gets in the way all the time and he haven't promised a deadline for this. Please try and show some respect...

Alexhha commented 8 years ago

Agree, but the issue has been opened 5 years ago! Does this feature require a lot of time to implement it? Because a lot of people really need it.

fardeem commented 8 years ago

I would kindly ask all the haters to read about forking and pull requests.

bedantaguru commented 8 years ago

Hey, don't blame the author please. They are doing it entirely for free. Only God does the same. It's very rude to tell this. If you want, develop it yourself.

Thanking you Indranil Gayen

On Sun, Jun 5, 2016 at 10:10 PM, Andrey Gadyukov notifications@github.com wrote:

I think the author is a liar and he never planned to release this feature.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ariya/phantomjs/issues/10052#issuecomment-223823148, or mute the thread https://github.com/notifications/unsubscribe/ACrtqe_LtWK0j6fhs7RIEdvz6wxeaK82ks5qIvwPgaJpZM4Ajhpl .

KhArtNJava commented 8 years ago

So many butt hurt in this thread :) )))))))))))))) .

masahirominami commented 8 years ago

hi, as i mentioned in my post (way back before already), in our case:

11484

did help. i believe it depends on what you are trying to do but it may work for otheres too. not sure of the latest phantomjs status but we are downloading files through phantomjs all right... and it's helping us a lot!

ariya commented 8 years ago

Just a friendly reminder: PhantomJS team consists of volunteers. We do not always have the spare time necessary to implement every feature request. Competing priorities are unavoidable.

If you can't live with this, see #13861 where I outlined various ways you can help us. If you're still not satisfied, pay your favorite consultant to contribute a feature. These are all way more productive than whining or even insulting our work.

geotheory commented 8 years ago

Please don't confuse those of us who have upvoted the feature request with the obnoxious comments above!

rmoriz commented 8 years ago

There is also the electron-based nightmare.js https://github.com/segmentio/nightmare which seems to perform a lot faster, too.

SeNaP commented 8 years ago

I rebased @Vitallium download-support on 2.1 https://github.com/SeNaP/phantomjs

Alexhha commented 8 years ago

Could you explain what does it mean? Can we already use download feature within phantomjs 2.1?

SeNaP commented 8 years ago

Yep

Clone repository https://github.com/SeNaP/phantomjs Build http://phantomjs.org/build.html

 page.onResourceReceived = function(response) {
            page.onFilePicker = function(){
                console.log("save file:"+filename);
                return "filename.extension"; // ex. file.zip
            }
        }
    }

    page.onDownloadFinished = function(status){
        console.log('onDownloadFinished(' + status + ')');
    }
    page.onLoadFinished = function(status){
        console.log('onLoadFinished(' + status + ')');
    }
Staf4 commented 8 years ago

SeNaP, you can do binary for windows? I do not know how to compile phantomjs (tried - did not work)

lanzorg commented 8 years ago

@SeNaP So why is it still not merged in the official phantomjs repository? Please could you explain me?

EndermanAPM commented 7 years ago

@lanzorg my wild guess is that the feature is only implemented on 2.1 and would not compile on the current master branch. Update1: @Staf4 After a retarded amount of time I managed to compile SeNaP version, although for some odd reason its quite large than the original, it's working just fine: --> phantomjs.zip Update2: @SeNaP Would your fork work with selenium(python)?

taiar commented 7 years ago

I built the linux-64 version of @SeNaP 's fork in this link: phantomjs.tar.gz

I'm trying to figure out how to use it with poltergeist (https://github.com/teampoltergeist/poltergeist) so I can download files with Capybara (https://github.com/teamcapybara/capybara). Any help is welcome.

JohnBruce commented 7 years ago

+1 😜

mynetx commented 7 years ago

Did someone manage to build a Mac version of @SeNaP ’s fork?

AnaPana-zz commented 7 years ago

+1 :100:

chadyred commented 7 years ago

+1

jomix commented 7 years ago

I built the osx binary of @SeNaP 's fork. https://github.com/jomix/phantomjs/raw/2.1/bin/phantomjs SHA1 bbecc70411c8094e95b7b8c6f3a1403cc7edc1e3 Enjoy.

rakeshnambiar commented 7 years ago

Has someone done it for Java-Selenium?

ankitgr8 commented 7 years ago

I have done it, but for which OS type Windows or Linux

On 08-May-2017 7:22 PM, "rakeshnambiar" notifications@github.com wrote:

Has someone done it for Java-Selenium?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/ariya/phantomjs/issues/10052#issuecomment-299872691, or mute the thread https://github.com/notifications/unsubscribe-auth/AGGCQKyCTLo46NSBdEl-msIviplbHbz8ks5r3x4xgaJpZM4Ajhpl .

rakeshnambiar commented 7 years ago

Hello @ankitgr8 ... I am looking for Windows.

Thanks

musanas commented 7 years ago

Hi @ankitgr8 I am also looking for the same . Just would like to know how we can set the default download directory if we use your phantom js exe and download the file in java-selenium

Many Thanks Musaffir

ankitgr8 commented 7 years ago

Here's the link to download the exe if any one required. https://github.com/ankitgr8/phantomjs2.0.. The above exe has the download capability. IT run on windows 64 bit.

To set the default download.. U can create the download JS at runtime and set the download directory at that time.. below is the sample of the js code which can be create using JAVA .. CHECK for "downloadFileName"

BufferedWriter bos = new BufferedWriter(fos); bos.append("var page = require('webpage').create(); "); for(Cookie ck : webDriver.manage().getCookies()) { bos.append(" phantom.addCookie({ name: '"+ck.getName()+"', value: '"+ck.getValue()+"', domain: '"+ck.getDomain()+"' }); "); bos.newLine(); }

bos.append(" page.onFileDownload = function(status){console.log('onFileDownload(' + status + ')'); return '"+downloadFileName+"'; }"); bos.newLine(); bos.append(" page.onResourceReceived = function(status){console.log('onResourceReceived(' + status.stage + ')'); if(status.stage === 'end'){phantom.exit(1);}}"); bos.newLine(); bos.append(" page.onResourceRequested = function(status){console.log('onResourceRequested(' + status + ')'); }"); bos.newLine(); bos.append(" page.onFileDownloadError = function(status){console.log('onFileDownloadError(' + status + ')');phantom.exit(1);}"); bos.newLine(); bos.append(" page.onLoadStarted = function(status){console.log('onLoadStarted(' + status + ')');}"); bos.newLine(); bos.append(" page.onLoadFinished = function(status){console.log('onLoadFinished(' + status + ')');}"); bos.newLine(); bos.append(" page.open('"+downloadURL+"');"); bos.flush(); bos.close();