# \[noob\] Parsing problems using https and redirects

**URL:** https://rubytalk.org/t/noob-parsing-problems-using-https-and-redirects/43032
**Category:** ruby-talk
**Created:** [14 December 2007 22:57 UTC](https://rubytalk.org/t/noob-parsing-problems-using-https-and-redirects/43032 "2007-12-14T22:57:36Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ramiro\_Diaz\_Trepat1](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@Ramiro\_Diaz\_Trepat1](https://rubytalk.org/u/Ramiro_Diaz_Trepat1)
#### Post date: [14 December 2007 22:57 UTC](https://rubytalk.org/t/noob-parsing-problems-using-https-and-redirects/43032/1 "2007-12-14T22:57:36Z")

</div>

Hello list,  
&nbsp;&nbsp;&nbsp;I have to develop a simple script to parse some parts of a web site and I  
thought it could be a good opportunity to start trying Ruby.  
&nbsp;&nbsp;&nbsp;I found that there are two network libraries that I could supposedly use  
to retrieve the contents of the web site: open-uri and net-http.

\*First problem\*  
&nbsp;&nbsp;&nbsp;This web site is accessed only with https and has a self issued  
certificate. This has made it impossible so far for me to access the  
contents of the web site.  
&nbsp;&nbsp;&nbsp;Simple examples from the Hpricot html parsing library like this one:

require 'hpricot'  
require 'open-uri'  
doc = Hpricot(open("[https://xxxxxx](https://xxxxxx)"))

&nbsp;&nbsp;&nbsp;will not work because the open will fail because of problems due to  
https.

\*Second problem\*  
&nbsp;&nbsp;&nbsp;I need to know also how to handle redirection and cookies. But to be  
fair, I still can do some further reading myself on these issues.

&nbsp;&nbsp;&nbsp;Thank you very much.

---

<div class="post-metadata">

### Author: ![Konrad\_Meyer](https://avatars.discourse-cdn.com/v4/letter/k/df705f/32.png) [@Konrad\_Meyer](https://rubytalk.org/u/Konrad_Meyer)
#### Post date: [15 December 2007 01:14 UTC](https://rubytalk.org/t/noob-parsing-problems-using-https-and-redirects/43032/2 "2007-12-15T01:14:24Z")

</div>

Quoth Ramiro Diaz Trepat:

> Hello list,  
> &nbsp;&nbsp;&nbsp;I have to develop a simple script to parse some parts of a web site and I  
> thought it could be a good opportunity to start trying Ruby.  
> &nbsp;&nbsp;&nbsp;I found that there are two network libraries that I could supposedly use  
> to retrieve the contents of the web site: open-uri and net-http.
> 
> \*First problem\*  
> &nbsp;&nbsp;&nbsp;This web site is accessed only with https and has a self issued  
> certificate. This has made it impossible so far for me to access the  
> contents of the web site.  
> &nbsp;&nbsp;&nbsp;Simple examples from the Hpricot html parsing library like this one:
> 
> require 'hpricot'  
> require 'open-uri'  
> doc = Hpricot(open("[https://xxxxxx](https://xxxxxx)"))
> 
> &nbsp;&nbsp;&nbsp;will not work because the open will fail because of problems due to  
> https.
> 
> \*Second problem\*  
> &nbsp;&nbsp;&nbsp;I need to know also how to handle redirection and cookies. But to be  
> fair, I still can do some further reading myself on these issues.
> 
> &nbsp;&nbsp;&nbsp;Thank you very much.

2) Look at mechanize.

1) Look at http-access2 (or whatever it's been renamed to).

Regards,

> **···**
>
> --  
> Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)

---

<div class="post-metadata">

### Author: ![Ramiro\_Diaz\_Trepat1](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@Ramiro\_Diaz\_Trepat1](https://rubytalk.org/u/Ramiro_Diaz_Trepat1)
#### Post date: [15 December 2007 05:48 UTC](https://rubytalk.org/t/noob-parsing-problems-using-https-and-redirects/43032/3 "2007-12-15T05:48:01Z")

</div>

Thank you very much Konrad, it seems that I am on my way now.  
The only weird thing that happened now with Mechanize is that it all works  
perfectly on my Linux but it doesn´t on my Mac/Leopard.  
Both have Ruby 1.8.6

On the mac I get the following error while trying to execute the first  
Mechanize example:

./mechanize.rb:4: uninitialized constant WWW (NameError)  
&nbsp;&nbsp;&nbsp;&nbsp;from /Library/Ruby/Site/1.8/rubygems/custom\_require.rb:27:in  
`gem\_original\_require'  
&nbsp;&nbsp;&nbsp;&nbsp;from /Library/Ruby/Site/1.8/rubygems/custom\_require.rb:27:in `require'  
&nbsp;&nbsp;&nbsp;&nbsp;from goog.rb:2

and the code is the first example of machanize:

require 'rubygems'  
require 'mechanize'

agent = WWW::Mechanize.new  
agent.user\_agent\_alias = 'Mac Safari'  
page = agent.get("[http://www.google.com/&quot;\](http://www.google.com/&quot;%5C))  
search\_form = page.forms.with.name("f").first  
search\_form.q = "Hello"  
search\_results = agent.submit(search\_form)  
puts search\_results.body

I really don't know why this constant is uninitialized and how could I  
initialize it. Besides it worries my that on Linux, after installing the  
mechanize gem, everything worked out of the box.

Thanks again

> **···**
>
> On Dec 14, 2007 10:14 PM, Konrad Meyer \<konrad@tylerc.org\> wrote:
> 
> > Quoth Ramiro Diaz Trepat:  
> > \> Hello list,  
> > \> I have to develop a simple script to parse some parts of a web site  
> > and I  
> > \> thought it could be a good opportunity to start trying Ruby.  
> > \> I found that there are two network libraries that I could supposedly  
> > use  
> > \> to retrieve the contents of the web site: open-uri and net-http.  
> > \>  
> > \> \*First problem\*  
> > \> This web site is accessed only with https and has a self issued  
> > \> certificate. This has made it impossible so far for me to access the  
> > \> contents of the web site.  
> > \> Simple examples from the Hpricot html parsing library like this one:  
> > \>  
> > \> require 'hpricot'  
> > \> require 'open-uri'  
> > \> doc = Hpricot(open("[https://xxxxxx](https://xxxxxx)"))  
> > \>  
> > \> will not work because the open will fail because of problems due to  
> > \> https.  
> > \>  
> > \> \*Second problem\*  
> > \> I need to know also how to handle redirection and cookies. But to be  
> > \> fair, I still can do some further reading myself on these issues.  
> > \>  
> > \> Thank you very much.
> > 
> > 2) Look at mechanize.
> > 
> > 1) Look at http-access2 (or whatever it's been renamed to).
> > 
> > Regards,  
> > --  
> > Konrad Meyer \<konrad@tylerc.org\> [http://konrad.sobertillnoon.com/](http://konrad.sobertillnoon.com/)
