0

I am looking for a way to download files from different pages and get them stored under a particular folder in a local machine. I am using Ruby 1.9.3

See the field below:

Filetypefield

File prompt to download

EDIT

here is the html content:

<input type="hidden" name="supplier.orgProfiles(1152444).location.locationPurposes().extendedAttributes(Upload_RFI_Form).value.filename" value="Screenshot.docx">

<a style="display:inline; position:relative;" href="

                                      /aems/file/filegetrevision.do?fileEntityId=8120070&cs=LU31NT9us5P9Pvkb1BrtdwaCrEraskiCJcY6E2ucP5s.xyz">
                                Screenshot.docx
                             </a>

One Possiblity I just tried: with the html content if add say https://xyz.test.com and construct the URL like as below

https://xyz.test.com/aems/file/filegetrevision.do?fileEntityId=8120070&cs=LU31NT9us5P9Pvkb1BrtdwaCrEraskiCJcY6E2ucP5s.xyz

and place that URL on to the browser and hit Enter giving me a chance to download the file as screenshot mentioned.

Now can it be done using Ruby via script?

Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317

1 Answers1

1

Since you didn't give a valid URL, it's difficult to test solutions for you.

In general, retrieving the content of a URL is the same, whether it's a page or a file. Ruby's built-in OpenURI is the fast path:

require 'open-uri'
file = open('http://example.com').read

Saving that file is easy:

IO.binwrite('/path/to/file_to_save', file)

Using binwrite avoids any line-end translations that would occur saving binary data. For text data use:

IO.write('/path/to/file_to_save', file)

Both IO.binwrite and IO.write are documented in the IO module.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
  • Can it handle the dialog box as i pasted aobve? – Arup Rakshit Jan 09 '13 at 21:33
  • `https://xyz.test.com/aems/file/filegetrevision.do?fileEntityId=8120070&cs=LU31NT9us5P9Pvkb1BrtdwaCrEraskiCJcY6E2ucP5s.xyz`is the downloadable file link. when you paste it to browser and hit `enter` command dialog box to get pop-up would arise. do your code save the file in that way or any other? – Arup Rakshit Jan 09 '13 at 21:36
  • You can't interface with a browser's dialog box directly, nor do you need to normally. The browser's GUI is not available to Ruby unless you use WATIR or one of its derivatives. – the Tin Man Jan 09 '13 at 21:42
  • Okay,I just need to download the file from the webpage,and the link is what I pasted. so your code will be able to do so. right? – Arup Rakshit Jan 09 '13 at 21:43
  • YOUR code, based on what we show you, will do it. On Stack Overflow, we don't necessarily provide a complete answer, only the parts you need to get started. And, so far, I haven't seen any code you've written. – the Tin Man Jan 09 '13 at 21:44
  • Yeah! i am happy to have it. Just asking! if any issue, i will paste my full code here! – Arup Rakshit Jan 09 '13 at 21:46
  • Your URL hangs with no response. – the Tin Man Jan 09 '13 at 21:47
  • Humm,I just gave a dummy URL, it is a logical one. as original one is my production url,so i didn't gave. to open that i have to share password also,which i shouldn't.:) – Arup Rakshit Jan 09 '13 at 21:49
  • Then you have NOT given us the information needed to help you. Your URL is behind a protected web server, which requires a different way of going after the data. I'd strongly recommend rewriting your question, completely covering the issues, specifying that the URL doesn't work (and why give one that doesn't work when we're supposed to help you download a file?). – the Tin Man Jan 09 '13 at 21:52
  • No i have a way to reach upto that page using `selenium` and i was finding some way to download the file, hope your help supports me. – Arup Rakshit Jan 09 '13 at 21:54