Nokogiri#css("input:disabled") not working

61 views
Skip to first unread message

Love U Ruby

unread,
Jun 1, 2013, 3:33:07 AM6/1/13
to rubyonra...@googlegroups.com
doc = Nokogiri::HTML::Document.parse(<<-eohtml)
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<form>
<input name="email" disabled="disabled" />
<input name="id" />
</form>
</body>
</html>
eohtml

p doc.css("input:disabled").count
# >> 2
# ~>
/home/kirti/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:159:in
`evaluate': xmlXPathCompOpEval: function disabled not found
(RuntimeError)
# ~> from
/home/kirti/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:159:in
`block in xpath'
# ~> from
/home/kirti/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:150:in
`map'
# ~> from
/home/kirti/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:150:in
`xpath'
# ~> from
/home/kirti/.rvm/gems/ruby-2.0.0-p0/gems/nokogiri-1.5.9/lib/nokogiri/xml/node.rb:214:in
`css'
# ~> from -:69:in `<main>'

************************
Why the errors are throwing up?

--
Posted via http://www.ruby-forum.com/.

Hassan Schroeder

unread,
Jun 1, 2013, 10:54:45 AM6/1/13
to rubyonra...@googlegroups.com
On Sat, Jun 1, 2013 at 12:33 AM, Love U Ruby <li...@ruby-forum.com> wrote:

> p doc.css("input:disabled").count

> Why the errors are throwing up?

What makes you think that's valid syntax?

--
Hassan Schroeder ------------------------ hassan.s...@gmail.com
http://about.me/hassanschroeder
twitter: @hassan

Love U Ruby

unread,
Jun 1, 2013, 11:04:07 AM6/1/13
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1110918:
Here I have seen. http://api.jquery.com/disabled-selector/

Hassan Schroeder

unread,
Jun 1, 2013, 11:29:41 AM6/1/13
to rubyonra...@googlegroups.com
On Sat, Jun 1, 2013 at 8:04 AM, Love U Ruby <li...@ruby-forum.com> wrote:

>> What makes you think that's valid syntax?

Uh, that's nice. But your question is about Nokogiri, not jQuery.

Love U Ruby

unread,
Jun 1, 2013, 11:35:48 AM6/1/13
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1110922:
> On Sat, Jun 1, 2013 at 8:04 AM, Love U Ruby <li...@ruby-forum.com>
> wrote:
>
>>> What makes you think that's valid syntax?
>
>> Here I have seen. http://api.jquery.com/disabled-selector/
>
> Uh, that's nice. But your question is about Nokogiri, not jQuery.

But Nokogiri supports jQuery css rules, but I found today some of the
css rules are not working.

Don't know why.. :(

Hassan Schroeder

unread,
Jun 1, 2013, 11:53:37 AM6/1/13
to rubyonra...@googlegroups.com
On Sat, Jun 1, 2013 at 8:35 AM, Love U Ruby <li...@ruby-forum.com> wrote:

> But Nokogiri supports jQuery css rules

Where in the Nokogiri docs does it say that? Where in the docs is
an example of the syntax you are trying to use?

Love U Ruby

unread,
Jun 1, 2013, 12:17:19 PM6/1/13
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1110928:

> Where in the Nokogiri docs does it say that? Where in the docs is
> an example of the syntax you are trying to use?

see below:

require "nokogiri"
doc = Nokogiri::HTML::Document.parse(<<-eohtml)
<html>
<head>
<style>
div { float:left; }
span { color:blue; }
</style>
</head>
<body>
<div>
<p>div1 p1</p>
<p>div1 p2</p>
<p>div1 p3</p>
<p>div1 p4</p>
</div>
<div>
<p>div2 p1</p>
<p>div2 p2</p>
<p>div2 p3</p>
<p>div2 p4</p>
</div>
</body>
</html>
eohtml

p doc.css("div p:eq(2)").map { |e| e.text }
# >> ["div1 p2", "div2 p2"]

Hassan Schroeder

unread,
Jun 1, 2013, 12:33:39 PM6/1/13
to rubyonra...@googlegroups.com
On Sat, Jun 1, 2013 at 9:17 AM, Love U Ruby <li...@ruby-forum.com> wrote:

>> Where in the Nokogiri docs does it say that? Where in the docs is
>> an example of the syntax you are trying to use?
>
> see below:

Uh, as I said -- in the docs?

> p doc.css("div p:eq(2)")

And in this case, what do you think 'eq' is ?

Love U Ruby

unread,
Jun 1, 2013, 12:47:51 PM6/1/13
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1110932:
> On Sat, Jun 1, 2013 at 9:17 AM, Love U Ruby <li...@ruby-forum.com>
> wrote:
>
>>> Where in the Nokogiri docs does it say that? Where in the docs is
>>> an example of the syntax you are trying to use?
>>
>> see below:
>
> Uh, as I said -- in the docs?
>
>> p doc.css("div p:eq(2)")
>
> And in this case, what do you think 'eq' is ?

This is a jQuery extension, and usable in Nokogiri. But some of the
rules are not working.

Hassan Schroeder

unread,
Jun 1, 2013, 1:15:58 PM6/1/13
to rubyonra...@googlegroups.com
On Sat, Jun 1, 2013 at 9:47 AM, Love U Ruby <li...@ruby-forum.com> wrote:

>> And in this case, what do you think 'eq' is ?
>
> This is a jQuery extension, and usable in Nokogiri. But some of the
> rules are not working.

Uh, sure. Whatever you want to believe. Good luck!

Love U Ruby

unread,
Jun 1, 2013, 1:28:16 PM6/1/13
to rubyonra...@googlegroups.com
Hassan Schroeder wrote in post #1110937:
> On Sat, Jun 1, 2013 at 9:47 AM, Love U Ruby <li...@ruby-forum.com>
> wrote:
>
>>> And in this case, what do you think 'eq' is ?
>>
>> This is a jQuery extension, and usable in Nokogiri. But some of the
>> rules are not working.
>
> Uh, sure. Whatever you want to believe. Good luck!

No sir, I am not telling I am wright. But I used them and working
perfectly. if you have any opinion lease share. :)

Thanks.

Tamara Temple

unread,
Jun 1, 2013, 3:40:50 PM6/1/13
to rubyonra...@googlegroups.com

So here is something I don't quite understand. According to [1],
"input:disabled" is a quite valid CSS selector.

Given this[2]:

<html><body>
<style>input:disabled {background: #0F0; color: #F00;}</style>
<input type="text" id="greenjunk" name="greenjunk" value="nada" disabled />
<input type="text" id="name" name="name" value="Joe" />
<input type="submit" id="submit" name="submit" value="submit" />
</body></html>

Why wouldn't doc.css("input:disabled") also work? Clearly it doesn't,
but I don't know what it *should* be. (Noting that xpath would be quite
different, of course.)



[1] https://developer.mozilla.org/en-US/docs/Web/CSS/:disabled
[2] see this ugly thing at https://dl.dropboxusercontent.com/u/571329/Examples/greenjunk.html

Love U Ruby

unread,
Jun 1, 2013, 4:01:50 PM6/1/13
to rubyonra...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages