# Intermittant problem with Hpricot

**URL:** <https://www.ruby-forum.com/t/intermittant-problem-with-hpricot/78184>\
**Category:** Rails\
**Created:** [December 3, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/intermittant-problem-with-hpricot/78184 "2006-12-03T18:45:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [December 3, 2006, 6:45pm UTC](https://www.ruby-forum.com/t/intermittant-problem-with-hpricot/78184/1 "2006-12-03T18:45:50Z")

</div>

Hi, I have already posted this question to the Ruby list, but it may be  
a Rails-related problem, so I’m cross-posting.

I’ve run into a wierd problem with the Hpricot gem. I don’t know if  
this is a problem with gems in general on my system, or if it’s specific  
to Hpricot, so I’m posting here.

Basically I have code as follows:  
require ‘rubygems’  
require ‘net/http’  
require ‘uri’  
require\_gem ‘hpricot’

class Page  
def some\_function(html\_text)  
doc = Hpricot(html\_text)  
doc.search("/html/body//img").each do |img|  
logger.debug("== Found an image: #{img} ==")  
src = img[/src="/]  
logger.debug(“src = #{src}”)  
end  
end  
end

When the function is called, sometimes I get a message saying that  
function Hpricot does not exist for the object of type Page. this  
continues for the entire programming session.

But sometimes, when I sit down to work on the project, the code works!  
It continues working until I restart the Rails server (this is a Rails  
project running on MacOSX).

Does anyone have any idea what might be causing this problem, and how to  
correct it?

Alli

---

<div class="post-metadata">

**Author:** ![demallien](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/85e7bf/32.png) [@demallien](https://www.ruby-forum.com/u/demallien)\
**Post date:** [December 3, 2006, 7:24pm UTC](https://www.ruby-forum.com/t/intermittant-problem-with-hpricot/78184/2 "2006-12-03T19:24:10Z")

</div>

Of interest, if I replace the  
doc = HPricot(html\_text)  
by  
doc = Hpricot.parse(html\_text)

everything works just fine, all of the time. But I still don’t  
understand why Rails doesn’t find the module level function all of the  
time. Anyone have any ideas?

Alli
