Skip to content

Instantly share code, notes, and snippets.

@leejarvis
Created September 3, 2012 13:02
Show Gist options
  • Save leejarvis/b018c3da03aca32dfc62 to your computer and use it in GitHub Desktop.
Save leejarvis/b018c3da03aca32dfc62 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'nokogiri'
doc = Nokogiri.HTML DATA
root_node = doc.at('font')
headline = doc.at('strong')
before = root_node.at('./text()[(following::br)]')
after = headline.at('./following::br/following::text()')
p before.text.strip #=> "Some foo bar text"
p headline.text.strip #=> "something"
p after.text.strip #=> "some other foo bar text"
__END__
<font size="2" face="Microsoft Sans Serif">
Some foo bar text
<br><br>
<strong>something</strong>
<br><br>
some other foo bar text
</font>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment