Skip to content

Instantly share code, notes, and snippets.

@robotmay
Created May 2, 2012 15:05
Show Gist options
  • Select an option

  • Save robotmay/2577270 to your computer and use it in GitHub Desktop.

Select an option

Save robotmay/2577270 to your computer and use it in GitHub Desktop.
Grabbing data between two elements with Nokogiri
def collect_between(first, last)
first == last ? [first] : [first, *collect_between(first.next, last)]
end
date_h3 = page.at_xpath("//h3[contains(text(), 'Date:')]")
time_h3 = page.at_xpath("//h3[contains(text(), 'Time:')]")
date_strings = collect_between(date_h3, time_h3)
date_strings[1..(date_strings.size - 2)].collect(&:text).delete_if(&:blank?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment