# Scraping websites

**URL:** <https://www.ruby-forum.com/t/scraping-websites/55854>\
**Category:** Ruby\
**Created:** [March 24, 2006, 9:20am UTC](https://www.ruby-forum.com/t/scraping-websites/55854 "2006-03-24T09:20:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 9:20am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/1 "2006-03-24T09:20:30Z")

</div>

Hi

I’m considering a side-project where I’d have to scrape a couple of  
websites and aggregate the results. So far I’ve done a couple of  
experiments with html-parser, but I’m not really happy with it. I’d  
hate to just throw regexps at the html, so I’m really looking for an  
elegant way to select the correct data from the page.

Any ideas on what gems to use?

Thanks  
Kev

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 9:24am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/2 "2006-03-24T09:24:22Z")

</div>

Hey Kev

Take a look at Rubyful Soup:

> **[Rubyful Soup: "The brush has got entangled in it!"](https://www.crummy.com/software/RubyfulSoup/)**
>
> Rubyful Soup: an HTML parser for Ruby, optimized for screen-scraping.

Very easy to parse X/HTML source, including the prevalent  
not-strictly-correct-and-even-somewhat-corrupt sort.

Regards,  
Alder

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 11:42am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/3 "2006-03-24T11:42:30Z")

</div>

Alder G. wrote:

> Hey Kev
> 
> Take a look at Rubyful Soup:
> 
> [Rubyful Soup: "The brush has got entangled in it!"](http://www.crummy.com/software/RubyfulSoup/)
> 
> Very easy to parse X/HTML source, including the prevalent  
> not-strictly-correct-and-even-somewhat-corrupt sort.

I’ve installed as a gem and now I’m getting unitialized constant  
BeautifulSoup errors

require ‘net/http’  
require ‘rubygems’  
require\_gem ‘rubyful\_soup’

class BBCScrape

def read  
Net::HTTP.start(“[news.bbc.co.uk](http://news.bbc.co.uk)”, 80) do |h|  
response =  
h.get(“/sport1/hi/football/eng\_prem/fixtures/default.stm”)  
#p response  
s = BeautifulSoup.new response.body ← fails  
p s.find\_all(‘div’, :attrs =\> { ‘class’ =\> ‘mvb’ })  
end  
end  
end

I’m not sure what I’m doing wrong and all the documentation doesn’t  
refer to gem usage

Sorry if this is me being thick at the end of a Friday…

Thanks  
Kev

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 11:44am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/4 "2006-03-24T11:44:58Z")

</div>

i have made good experience using watir ([http://wtr.rubyforge.org/](http://wtr.rubyforge.org/) and  
[Macro Scheduler - Macro Recorder And Windows Robotic Process Automation Tool](http://www.mjtnet.com/watir_webrecorder.htm)) - buts its an windows only  
thing.

also very usable (and cross plattform) is www:mechanize  
([http://www.ntecs.de/blog/Blog/WWW-Mechanize.rdoc](http://www.ntecs.de/blog/Blog/WWW-Mechanize.rdoc)).

hope this helps,

lars

Kev J. schrieb:

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 11:56am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/5 "2006-03-24T11:56:27Z")

</div>

lg wrote:

> i have made good experience using watir ([http://wtr.rubyforge.org/](http://wtr.rubyforge.org/) and  
> [Macro Scheduler - Macro Recorder And Windows Robotic Process Automation Tool](http://www.mjtnet.com/watir_webrecorder.htm)) - buts its an windows only  
> thing.

I know how to use watir - it’s great, but it’s not the correct approach  
for this application - I want to request a page from a remote source and  
extract data from it - rubyful soup seems like the way to go, but for  
some reason I’m having difficulty with the code. Watir is good for  
driving a browser - I’m not interested in that for this application

Thanks  
Kev

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 1:12pm UTC](https://www.ruby-forum.com/t/scraping-websites/55854/6 "2006-03-24T13:12:53Z")

</div>

On Fri, 2006-03-24 at 19:42 +0900, Kev J. wrote:

> > 
> 
> I’ve installed as a gem and now I’m getting unitialized constant  
> BeautifulSoup errors

See this post from yesterday:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185578](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185578)

but watch out for the typo (I meant “_doesn’t_ (by default) actually  
require anything”)

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 1:17pm UTC](https://www.ruby-forum.com/t/scraping-websites/55854/7 "2006-03-24T13:17:27Z")

</div>

On Mar 24, 2006, at 1:12 PM, Ross B. wrote:

> See this post from yesterday:
> 
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185578](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185578)
> 
> but watch out for the typo (I meant “_doesn’t_ (by default) actually  
> require anything”)

Also, check out this recent thread:

[http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185581](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185581)

– Daniel

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 24, 2006, 5:51pm UTC](https://www.ruby-forum.com/t/scraping-websites/55854/8 "2006-03-24T17:51:58Z")

</div>

lg wrote:

> i have made good experience using watir ([http://wtr.rubyforge.org/](http://wtr.rubyforge.org/) and  
> [Macro Scheduler - Macro Recorder And Windows Robotic Process Automation Tool](http://www.mjtnet.com/watir_webrecorder.htm)) - buts its an windows only  
> thing.
> 
> also very usable (and cross plattform) is www:mechanize  
> ([http://www.ntecs.de/blog/Blog/WWW-Mechanize.rdoc](http://www.ntecs.de/blog/Blog/WWW-Mechanize.rdoc)).

This may help you with Mechanize:

> **[How I Did It: Building RubyStuff.com](https://neurogami.com/cafe-fetcher/)**
>
> A microformat that eases the transition from page to print with CSS and HTML

–  
James B.

[http://web2.0validator.com](http://web2.0validator.com) - We’re the Dot in Web 2.0  
[http://refreshingcities.org](http://refreshingcities.org) - Design, technology, usability  
[http://yourelevatorpitch.com](http://yourelevatorpitch.com) - Finding Business Focus  
[http://www.jamesbritt.com](http://www.jamesbritt.com) - Playing with Better Toys

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 27, 2006, 3:14am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/9 "2006-03-27T03:14:43Z")

</div>

> See this post from yesterday:
> 
> [http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185578](http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/185578)
> 
> but watch out for the typo (I meant “_doesn’t_ (by default) actually  
> require anything”)

Thanks! Just tried and worked perfectly. I’ve always used

require ‘rubygems’  
require\_gem ‘x’

before, so now I know if that fails to try:

require ‘rubygems’  
require ‘x’

Again thanks for the help in resolving this. Learnt something today, so  
it’s not a wasted day 🙂

Kev

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 28, 2006, 6:39am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/10 "2006-03-28T06:39:22Z")

</div>

Kev J. wrote:

> Thanks  
> Kev

Look at SWExplorerAutomation ([www.webunittesting.com](http://www.webunittesting.com))  
The program creates an automation API for any Web application which  
uses HTML and DHTML and works with Microsoft Internet Explorer. The Web  
application becomes programmatically accessible from any .NET language.

SWEA API provides access to Web application controls and content. The  
API is generated using SWEA Visual Designer. SWEA Visual Designer helps  
create programmable objects from Web page content.

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 28, 2006, 8:48am UTC](https://www.ruby-forum.com/t/scraping-websites/55854/11 "2006-03-28T08:48:17Z")

</div>

> 

Perhaps you’ve misunderstood my intentions. I want to scrape a website  
(BBC News for example) and extract some data from the HTML returned. I  
want to use Ruby to do this and I also want to avoid using regular  
expressions to manually parse the HTML myself.

Forgive me if I’m wrong, but your response seems to be an advert for an  
automation product for .Net.

Someone else has already suggested RubyfulSoup which I’ve had some  
success with and I’m moving ahead with this for now.

Kev

---

<div class="post-metadata">

**Author:** ![Kev\_J](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/2bfe46/32.png) [@Kev\_J](https://www.ruby-forum.com/u/Kev_J)\
**Post date:** [March 28, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/scraping-websites/55854/12 "2006-03-28T14:28:59Z")

</div>

1. You don’t have to use regular expressions to extract data. SWEA  
works with XML and have XpathDataExtractor and TableDataExtractor to  
simplify the data extraction.  
You can visually define the the extraction rules using them.

2. You can use [Ruby.Net](http://Ruby.Net) for automation scripts and I like .Net.

3. SWEA supports frames, javascript, popup windows, windows and html  
dialog boxes, file and image downloads with cookies and etc.Also SWEA  
can work from windows service account.

SWEA have been used in many data scraping solutions with a great  
success. Look at SWJobSearch. I have wrote it in a few days. Try to  
write it using RubyfulSoup.

Good luck with RubyfulSoup!
