Created
May 2, 2012 15:05
-
-
Save robotmay/2577270 to your computer and use it in GitHub Desktop.
Grabbing data between two elements with Nokogiri
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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