Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:first-child not working when selecting on .class #28

Closed
morganchristiansson opened this issue Feb 14, 2010 · 2 comments
Closed

:first-child not working when selecting on .class #28

morganchristiansson opened this issue Feb 14, 2010 · 2 comments

Comments

@morganchristiansson
Copy link

require 'rubygems'
require 'mechanize'

agent=Mechanize.new
agent.user_agent='wget' # default user-agent string is banned apparantly
page=agent.get('http://en.wikipedia.org/wiki/Comparison_of_file_archivers')

page.search('table.wikitable:first-child') #does not work
page.search('.wikitable:first-child')      #does not work
page.search('table:first-child')           #works - but it's not a .wikitable table
page.search('table.wikitable')             #works - returns 5 tables

The error is:

> page.search('table.wikitable:first-child')
RuntimeError: xmlXPathCompOpEval: function first-child not found
from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:142:in `evaluate'
from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:142:in `xpath'
from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:139:in `map'
from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:139:in `xpath'
from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:106:in `search'
from (irb):119
from /usr/local/lib/site_ruby/1.8/rubygems.rb:168

RuntimeError: xmlXPathCompOpEval: function first-child not found

  from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:142:in `evaluate'
  from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:142:in `xpath'
  from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:139:in `map'
  from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:139:in `xpath'
  from /usr/lib/ruby/gems/1.8/gems/nokogiri-1.4.0/lib/nokogiri/xml/node.rb:106:in `search'
  from (irb):119
  from /usr/local/lib/site_ruby/1.8/rubygems.rb:168

Using Mechanize 1.0.0.

@drbrain
Copy link
Member

drbrain commented Apr 3, 2011

There is no table that has a class of 'wikitable' and is a first-child in that document.

Perhaps you mean 'table.wikitable :first-child' (the tbody).

@drbrain drbrain closed this as completed Apr 3, 2011
@morganchristiansson
Copy link
Author

Oh is that how it works. I think what I was after was the first matched element like page.search('xxx')[0] or LIMIT 1 in SQL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants