I want to build a simple website that can download a webpage www.example.com/index.html and store its snapshot on the server when the client requests. I’m thinking about using the command wget to download the webpage. Would Ruby on Rails be able to handle this task?
I want to build a simple website that can download a webpage www.example.com/index.html and
Share
Yes.
You can perform shell commands in Ruby via back ticks, exec and system. Note that each one returns something slightly different:
back ticks
exec:system:This blog post seems to be in the same vein as what you’re trying to do.
Additionally, there are several terrific Ruby libraries for doing this:
They will provide a much better cleaner Ruby interface for dealing with the data that comes back from the various requests.
The best way to test all of these options is to use the Rails console. Go to the root directory of your Rails app and type:
Once in the console, you can emulate the actual server calls.
Running
wgetin your console will drop the files in your Rails root directory, which is not what you want.tmpis a standard directory for such things. You can dynamically generate the path based on the URL like so:Be sure to also include the options from this post