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
endcheat sheets.
$ cheat hpricot( add new | see all )
- updated sheets

- shoulda
- capistrano
- rpm
- string
- sqld4r
- cheat_el
- cheat
- magit
- to_i
- bm
- rails_date_formats
- sequel
- dexagogo_form_validation
- git
- git_remote_branch
Advertisement