# Best way to download an antire site with ruby

**URL:** <https://www.ruby-forum.com/t/best-way-to-download-an-antire-site-with-ruby/178328>\
**Category:** Ruby\
**Created:** [November 2, 2009, 11:51pm UTC](https://www.ruby-forum.com/t/best-way-to-download-an-antire-site-with-ruby/178328 "2009-11-02T23:51:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![addame](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@addame](https://www.ruby-forum.com/u/addame)\
**Post date:** [November 2, 2009, 11:51pm UTC](https://www.ruby-forum.com/t/best-way-to-download-an-antire-site-with-ruby/178328/1 "2009-11-02T23:51:03Z")

</div>

What is the best way to download all Web S. resources (html, images,  
…) to a local directory using Ruby?  
Thanks,  
A.

---

<div class="post-metadata">

**Author:** ![addame](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@addame](https://www.ruby-forum.com/u/addame)\
**Post date:** [November 3, 2009, 8:14am UTC](https://www.ruby-forum.com/t/best-way-to-download-an-antire-site-with-ruby/178328/2 "2009-11-03T08:14:37Z")

</div>

med addame wrote:

> What is the best way to download all Web S. resources (html, images,  
> …) to a local directory using Ruby?  
> Thanks,  
> A.

I’d say Hpricot + Net::HTTP

> **[GitHub - whymirror/hpricot: A swift, liberal HTML parser with a fantastic...](https://github.com/whymirror/hpricot)**
>
> A swift, liberal HTML parser with a fantastic library - GitHub - whymirror/hpricot: A swift, liberal HTML parser with a fantastic library

something like…

class Page  
attr\_accessor :html  
attr\_accessor :links

def open  
#… do net http open here  
end

def save  
# save html as .html  
# save images …  
# for each link that are from anchor tags  
# - create a new page  
# - call open/parse/save  
end

def parse\_links  
#… use hpricot here to parse links  
#… add them to an @links array  
#… give them each a type (img,anchor,etc)  
end  
end

---

<div class="post-metadata">

**Author:** ![addame](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ecd19e/32.png) [@addame](https://www.ruby-forum.com/u/addame)\
**Post date:** [November 3, 2009, 12:15pm UTC](https://www.ruby-forum.com/t/best-way-to-download-an-antire-site-with-ruby/178328/3 "2009-11-03T12:15:01Z")

</div>

med addame wrote:

> What is the best way to download all Web S. resources (html, images,  
> …) to a local directory using Ruby?

Quickest and easiest:

system(“wget -p -np -r [Lua 5.1 Reference Manual - contents](http://www.lua.org/manual/5.1/)”)

Also useful are the -I, -P, -nH options.
