# Nokogiri not read html file in Cent OS 32-bit

**URL:** <https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816>\
**Category:** ruby-talk\
**Created:** [12 November 2010 11:53 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816 "2010-11-12T11:53:54Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Priyank\_Shah](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Priyank\_Shah](https://rubytalk.org/u/Priyank_Shah)\
**Post date:** [12 November 2010 11:53 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816/1 "2010-11-12T11:53:54Z")

</div>

Hi all,

I want to read and use html file content using Nokogiri in my cent os-32  
bit

but it not read any html contents.

@test = Nokogiri::HTML("abc.html")  
puts "#{@test}"

but it just shows me java scripts on source page not any html contents.

please reply me if any one know about this issue.

Thanks,  
Priyank Shah

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Ryan\_Davis1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/ryan_davis1/32/1848_2.png) [@Ryan\_Davis1](https://rubytalk.org/u/Ryan_Davis1)\
**Post date:** [12 November 2010 21:21 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816/2 "2010-11-12T21:21:52Z")

</div>

503 % ri Nokogiri.HTML  
= Nokogiri.HTML

(from gem nokogiri-1.4.3.1)

> **···**
>
> On Nov 12, 2010, at 05:53 , Priyank Shah wrote:
> 
> > @test = Nokogiri::HTML("abc.html")
> 
> ----------------------------------------------------------------------------  
> &nbsp;&nbsp;HTML(thing, url = nil, encoding = nil, options = XML::ParseOptions::DEFAULT\_HTML, &block)
> 
> ----------------------------------------------------------------------------
> 
> Parse HTML. Convenience method for Nokogiri::HTML::Document.parse
> 
> ---
> 
> thing is not a path.

---

<div class="post-metadata">

**Author:** ![Priyank\_Shah](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Priyank\_Shah](https://rubytalk.org/u/Priyank_Shah)\
**Post date:** [15 November 2010 05:55 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816/3 "2010-11-15T05:55:14Z")

</div>

Ryan Davis wrote in post #961099:

> > @test = Nokogiri::HTML("abc.html")
> 
> 503 % ri Nokogiri.HTML  
> = Nokogiri.HTML
> 
> (from gem nokogiri-1.4.3.1)  
> ----------------------------------------------------------------------------  
> &nbsp;&nbsp;HTML(thing, url = nil, encoding = nil, options =  
> XML::ParseOptions::DEFAULT\_HTML, &block)

hi,

Thanks for reply but not getting solution i get only

\<!DOCTYPE html public \"-//W3C DTD HTML 4.0 Tansitional//EN\" .....

as a output, not actual html contents in file.

I check nokogiri but i think it is some html character set encoding  
issue.

can you give me some idea about this?

Thanks,  
Priyank Shah

> **···**
>
> > On Nov 12, 2010, at 05:53 , Priyank Shah wrote:
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Florian\_Gilcher](https://avatars.discourse-cdn.com/v4/letter/f/57b2e6/32.png) [@Florian\_Gilcher](https://rubytalk.org/u/Florian_Gilcher)\
**Post date:** [15 November 2010 08:18 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816/4 "2010-11-15T08:18:07Z")

</div>

What Ryan is telling you: you have to pass a filepointer or the actual HTML as string, not a string containing a filename.

> **···**
>
> Am 15.11.2010 um 06:55 schrieb Priyank Shah \<shahpriyank01@gmail.com\>:
> 
> > Ryan Davis wrote in post #961099:
> > 
> > > On Nov 12, 2010, at 05:53 , Priyank Shah wrote:
> > > 
> > > > @test = Nokogiri::HTML("abc.html")
> > > 
> > > 503 % ri Nokogiri.HTML  
> > > = Nokogiri.HTML
> > > 
> > > (from gem nokogiri-1.4.3.1)  
> > > ----------------------------------------------------------------------------  
> > > HTML(thing, url = nil, encoding = nil, options =  
> > > XML::ParseOptions::DEFAULT\_HTML, &block)
> > 
> > hi,
> > 
> > Thanks for reply but not getting solution i get only
> > 
> > \<!DOCTYPE html public \"-//W3C DTD HTML 4.0 Tansitional//EN\" .....
> > 
> > as a output, not actual html contents in file.
> > 
> > I check nokogiri but i think it is some html character set encoding  
> > issue.
> > 
> > can you give me some idea about this?
> > 
> > Thanks,  
> > Priyank Shah
> > 
> > --  
> > Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Priyank\_Shah](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Priyank\_Shah](https://rubytalk.org/u/Priyank_Shah)\
**Post date:** [15 November 2010 08:56 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816/5 "2010-11-15T08:56:44Z")

</div>

Florian Gilcher wrote in post #961470:

> What Ryan is telling you: you have to pass a filepointer or the actual  
> HTML as string, not a string containing a filename.

hi,

Thanks for explain but still i get the same problem

i us following in cent Os-5.5 32 bit

$\> nokogiri -v

Ruby

engine:mri  
version:1.8.7  
platform:i686-linux

libxml:

loaded: 2.6.26  
binding: extension  
complied:2.6.26  
nokogiri:1.4.3.1

> **···**
>
> --------  
> my code is like
> 
> f = File.open("test.html")  
> data = Nokogiri::HTML(f)  
> puts "#{data}"
> 
> p "#{data}"
> 
> but any of this give
> 
> Output:
> 
> "\<!DOCTYPE html PUBLIC \"-W3C//DTD HTML 4.0 Transitional//EN\" .......
> 
> this type of output it shows not get actual html contents.
> 
> So help me if you have any more idea.
> 
> Thanks,  
> Priyank Shah
> 
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![niklas\_brueckenschla](https://avatars.discourse-cdn.com/v4/letter/n/41988e/32.png) [@niklas\_brueckenschla](https://rubytalk.org/u/niklas_brueckenschla)\
**Post date:** [15 November 2010 09:11 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816/6 "2010-11-15T09:11:01Z")

</div>

Can't reproduce your problem. Try this:

&nbsp;&nbsp;require 'rubygems'  
&nbsp;&nbsp;require 'nokogiri'  
&nbsp;&nbsp;# make sure the file contains sth.  
&nbsp;&nbsp;File.open('test.html', 'w') {|f|  
&nbsp;&nbsp;&nbsp;&nbsp;f.write("\<html\>\<body\>\<h1\>Foo\</h1\>\</body\>\</html\>") }

&nbsp;&nbsp;f = File.open('test.html')  
&nbsp;&nbsp;data = Nokogiri::HTML(f)  
&nbsp;&nbsp;puts data  
&nbsp;&nbsp;p data

----- OUTPUT ------

&nbsp;&nbsp;\<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"  
&nbsp;&nbsp;"[http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt](http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt);  
&nbsp;&nbsp;\<html\>\<body\>\<h1\>Foo\</h1\>\</body\>\</html\>  
&nbsp;&nbsp;#\<Nokogiri::HTML::Document:0x3ff244a4fb70 name="document"  
&nbsp;&nbsp;children=[#\<Nokogiri::XML::DTD:0x3ff244ad5e14 name="html"\>,  
&nbsp;&nbsp;#\<Nokogiri::XML::Element:0x3ff244adf5b8 name="html"  
&nbsp;&nbsp;children=[#\<Nokogiri::XML::Element:0x3ff244b50e0c name="body"  
&nbsp;&nbsp;children=[#\<Nokogiri::XML::Element:0x3ff244b50b28 name="h1"  
&nbsp;&nbsp;children=[#\<Nokogiri::XML::Text:0x3ff244b508a8 "Foo"\>]\>]\>]\>]\>

> **···**
>
> On Mon, 2010-11-15 at 17:56 +0900, Priyank Shah wrote:
> 
> > Florian Gilcher wrote in post #961470:  
> > \> What Ryan is telling you: you have to pass a filepointer or the actual  
> > \> HTML as string, not a string containing a filename.
> > 
> > hi,
> > 
> > Thanks for explain but still i get the same problem
> > 
> > i us following in cent Os-5.5 32 bit
> > 
> > $\> nokogiri -v
> > 
> > Ruby
> > 
> > engine:mri  
> > version:1.8.7  
> > platform:i686-linux
> > 
> > libxml:
> > 
> > loaded: 2.6.26  
> > binding: extension  
> > complied:2.6.26  
> > nokogiri:1.4.3.1
> > 
> > --------  
> > my code is like
> > 
> > f = File.open("test.html")  
> > data = Nokogiri::HTML(f)  
> > puts "#{data}"
> > 
> > p "#{data}"
> > 
> > but any of this give
> > 
> > Output:
> > 
> > "\<!DOCTYPE html PUBLIC \"-W3C//DTD HTML 4.0 Transitional//EN\" .......
> > 
> > this type of output it shows not get actual html contents.
> > 
> > So help me if you have any more idea.
> > 
> > Thanks,  
> > Priyank Shah

---

<div class="post-metadata">

**Author:** ![Priyank\_Shah](https://avatars.discourse-cdn.com/v4/letter/p/f08c70/32.png) [@Priyank\_Shah](https://rubytalk.org/u/Priyank_Shah)\
**Post date:** [15 November 2010 10:04 UTC](https://rubytalk.org/t/nokogiri-not-read-html-file-in-cent-os-32-bit/60816/7 "2010-11-15T10:04:08Z")

</div>

Niklas Cathor wrote in post #961490:

> Can't reproduce your problem. Try this:
> 
> &nbsp;&nbsp;require 'rubygems'  
> &nbsp;&nbsp;require 'nokogiri'  
> &nbsp;&nbsp;# make sure the file contains sth.  
> &nbsp;&nbsp;File.open('test.html', 'w') {|f|  
> &nbsp;&nbsp;&nbsp;&nbsp;f.write("\<html\>\<body\>\<h1\>Foo\</h1\>\</body\>\</html\>") }
> 
> &nbsp;&nbsp;f = File.open('test.html')  
> &nbsp;&nbsp;data = Nokogiri::HTML(f)  
> &nbsp;&nbsp;puts data  
> &nbsp;&nbsp;p data
> 
> ----- OUTPUT ------
> 
> &nbsp;&nbsp;\<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"  
> &nbsp;&nbsp;"[http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt](http://www.w3.org/TR/REC-html40/loose.dtd&quot;&gt);  
> &nbsp;&nbsp;\<html\>\<body\>\<h1\>Foo\</h1\>\</body\>\</html\>  
> &nbsp;&nbsp;#\<Nokogiri::HTML::Document:0x3ff244a4fb70 name="document"  
> &nbsp;&nbsp;children=[#\<Nokogiri::XML::DTD:0x3ff244ad5e14 name="html"\>,  
> &nbsp;&nbsp;#\<Nokogiri::XML::Element:0x3ff244adf5b8 name="html"  
> &nbsp;&nbsp;children=[#\<Nokogiri::XML::Element:0x3ff244b50e0c name="body"  
> &nbsp;&nbsp;children=[#\<Nokogiri::XML::Element:0x3ff244b50b28 name="h1"  
> &nbsp;&nbsp;children=[#\<Nokogiri::XML::Text:0x3ff244b508a8 "Foo"\>]\>]\>]\>]\>

Hi,

First thanks to all for helping me in my problem.

I got the solution finally,

I tried

f = open("test.html").read  
data = Nokogiri::HTML(f)  
puts data  
instead of

f = FIle.open("test.html")  
data = Nokogiri::HTML(f)  
puts data

and i get html data.

so basically i don't use File class.

Thanks,  
Priyank Shah

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
