cheat sheets.

$ cheat hpricot
--- hpricot version 2	Tue Jan 16 22:59:00 +0000 2007
+++ hpricot version 3	Tue Jan 16 22:59:10 +0000 2007
@@ -1,29 +1,41 @@
 Element#css_path
 
  doc.at("div > div:nth(1)").css_path
    #=> "div > div:nth(1)" 
  doc.at("#header").css_path
    #=> "#header" 
 
 Element#xpath
 
  doc.at("div > div:nth(1)").xpath
    #=> "/div/div:eq(1)" 
  doc.at("#header").xpath
    #=> "//div[@id='header']" 
 
 Element#swap
 
  doc = Hpricot("That's my <b>spoon</b>, Tyler.")
  doc.at("b").swap("<i>fork</i>")
  doc.to_html
    #=> "That's my <i>fork</i>, Tyler." 
 
 Element#next_sibling, Element#previous_sibling
 
  (doc/:h3).each do |h3|
    while ele = h3.next_sibling
      ary << ele   # stuff away all the elements under the h3
    end
  end
+
+###########################################
+
+elements = doc.search(&quot;a&quot;)
+elements = doc.search(&quot;a.class&quot;)
+elements = doc.search(&quot;a#ID&quot;)
+elements = doc.search(&quot;body &gt; table &gt; a&quot;)
+elements = doc.search(&quot;a[@href='http://hoodwink.d/']&quot;)
+element  = doc.at(&quot;a#ID&quot;) == doc.search(&quot;a#ID&quot;).first
+attribute = doc.at(&quot;body&quot;)['onload'] == doc.at(&quot;body&quot;)[:onload]
+elements = doc.search(&quot;table &gt; a#ID&quot;) == (doc/&quot;table &gt; a#ID&quot;) ==
+(doc/&quot;table/a#ID&quot;) == (doc/:table/:a#ID)
( add new | see all )