Created
February 11, 2015 06:25
-
-
Save aruprakshit/47ce52832b716b5eda55 to your computer and use it in GitHub Desktop.
difference between Nokogiri::HTML::DocumentFragment and Nokogiri::HTML::Document
This file contains 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
require 'nokogiri' | |
doc = Nokogiri::HTML::Document.parse <<-html | |
<table style="width:100%"> | |
<tr> | |
<td>Jill</td> | |
<td>Smith</td> | |
<td>50</td> | |
</tr> | |
<tr> | |
<td>Eve</td> | |
<td>Jackson</td> | |
<td>94</td> | |
</tr> | |
</table> | |
html | |
puts doc.xpath("//table/tr").count # 2 |
This file contains 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
require 'nokogiri' | |
doc = Nokogiri::HTML::DocumentFragment.parse <<-html | |
<table style="width:100%"> | |
<tr> | |
<td>Jill</td> | |
<td>Smith</td> | |
<td>50</td> | |
</tr> | |
<tr> | |
<td>Eve</td> | |
<td>Jackson</td> | |
<td>94</td> | |
</tr> | |
</table> | |
html | |
puts doc.xpath("//table/tr").count # 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Github Link for this.
Here is the difference