Some example:
require 'nokogiri'
html = %Q{
<!DOCTYPE html>
<body>
<div id='im$the$div'></div>
</body>}
page = Nokogiri::HTML( html )
page.css('#im$the$div')
# => Nokogiri::CSS::SyntaxError: unexpected '$' after '[#<Nokogiri::CSS::Node:0x000000039fe5b8 @type=:CONDITIONAL_SELECTOR, @value=[#<Nokogiri::CSS::Node:0x000000039fe608 @type=:ELEMENT_NAME, @value=["*"]>, #<Nokogiri::CSS::Node:0x000000039fe748 @type=:ID, @value=["#im"]>]>]'
but you can use XPath selector:
page.xpath("//div[@id='im$the$div']")
# => [#<Nokogiri::XML::Element:0x1a8f59c name="div" attributes=[#<Nokogiri::XML::Attr:0x1a8f344 name="id" value="im$the$div">] children=[#<Nokogiri::XML::Text:0x1a8e598 "\n">]>]
page.xpath("//div[@id='im$the$div']")[0].attr(:id)
# => "im$the$div"