I have an html element like:
<div id="spam[500]">
I want to search for this element by id, but it seems that nokogiri is getting confused by the []. I'm trying:
doc.css("#spam[#{eggs.id}]")
but to no avail.
I have an html element like:
<div id="spam[500]">
I want to search for this element by id, but it seems that nokogiri is getting confused by the []. I'm trying:
doc.css("#spam[#{eggs.id}]")
but to no avail.
Chris, try this and let me know if it works:
doc = Nokogiri::HTML(page)
el = doc.xpath("//div[@id='spam[500]']").first
The problem is that you can't access it via CSS (even in the browser). Try setting some CSS attributes for "spam[500]" and they won't be applied. You can access via xpath however, as shown above.
The real problem here is that the characters [ and ] are illegal in an HTML4 (or XML) id attribute - look at the following:
http://www.w3.org/TR/html401/types.html#type-name
(for the normative definition of the id attribute look at www.w3.org//TR/html401/struct/global.html#adef-id)