user1023482
user1023482

Reputation: 15

Retuning empty webpages when writing the contents of wget in Ruby

I am trying to a save a website to an HTML file using Ruby. When I open the file, the website is empty.

Currently trying:

doc = system("wget -r -l 1 http://google.com")
my_file = 'google.html'  
f = File.open(my_file, 'w')  
f.write(doc)  
f.close  

I can get it working using Nokogiri, but I'm trying to keep it as simplistic as possible.

Upvotes: 0

Views: 203

Answers (1)

Leonid Shevtsov
Leonid Shevtsov

Reputation: 14189

I advise you to use Net::HTTP instead of any external utility to download pages in Ruby.

But if you must, read this article on calling programs from Ruby.

Basically you must call (backtick)wget ...(backtick) (sorry about the parser) or %x[wget ...] instead of system if you're interested in the program's output.

Upvotes: 1

Related Questions