undefined method `name' for "ISO-8859-1":String

49 views
Skip to first unread message

Caleb Sayre

unread,
Jul 6, 2016, 7:52:51 AM7/6/16
to nokogiri-talk
I keep getting this error when trying to use Nokogiri.  Here is what I am doing:
agent = Mechanize.new
html = agent.get('http://www.j-archive.com/showgame.php?game_id=173')
Nokogiri::HTML(html)
NoMethodError: undefined method `name' for "ISO-8859-1":String
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/nokogiri-1.6.8/lib/nokogiri/html/document.rb:169:in `parse'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/nokogiri-1.6.8/lib/nokogiri/html.rb:15:in `HTML'
from (irb):3
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/console.rb:65:in `start'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/console_helper.rb:9:in `start'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:78:in `console'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `block in require'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:293:in `require'
from /Users/calebsayre/Documents/Programming/jeopardy/bin/rails:9:in `<top (required)>'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `block in load'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:259:in `load_dependency'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/activesupport-5.0.0/lib/active_support/dependencies.rb:287:in `load'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/commands/rails.rb:6:in `call'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/command_wrapper.rb:38:in `call'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:191:in `block in serve'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:161:in `fork'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:161:in `serve'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:131:in `block in run'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `loop'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application.rb:125:in `run'
from /Users/calebsayre/.rvm/gems/ruby-2.3.1/gems/spring-1.7.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /Users/calebsayre/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/calebsayre/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'

I dont think I am doing anything wrong.  This is usually how I use Nokogiri and Mechanize and have not seen this issue before.

Hassan Schroeder

unread,
Jul 6, 2016, 11:44:49 AM7/6/16
to nokogi...@googlegroups.com
On Tue, Jul 5, 2016 at 6:29 PM, Caleb Sayre <drs...@gmail.com> wrote:
> I keep getting this error when trying to use Nokogiri. Here is what I am
> doing:
> agent = Mechanize.new
> html = agent.get('http://www.j-archive.com/showgame.php?game_id=173')
> Nokogiri::HTML(html)

I honestly don't see how that could ever work - agent.get() returns
a Mechanize *page object*, not a string of html.

page = agent.get('http://www.j-archive.com/showgame.php?game_id=173')
Nokogiri::HTML(page.content)

should work, though.

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Consulting Availability : Silicon Valley or remote

Caleb Sayre

unread,
Jul 6, 2016, 2:04:02 PM7/6/16
to nokogiri-talk
Thanks hassan, I knew there was a silly mistake I was making.
Reply all
Reply to author
Forward
0 new messages