Created
October 21, 2015 13:55
-
-
Save akwiatkowski/b898347961c0a0d0d8aa to your computer and use it in GitHub Desktop.
Sample xpath html parse in crystal
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
require "xml" | |
s = " | |
<dic class='container'> | |
<div class=\"main\"> | |
<div class=\"ca\" id=\"ia\">a</div> | |
<span class=\"cb\" id=\"ib\">b</span> | |
</div> | |
<div class=\"main2\"> | |
<div class=\"ca\" id=\"ia\">a2</div> | |
<span class=\"cb\" id=\"ib\">b2</span> | |
</div> | |
</div>" | |
xml = XML.parse_html(s) | |
# node = xml.xpath_node("//*[contains(@class, 'cb')]") | |
# puts "txt #{node.inner_text}" | |
# puts "inner #{node.inner_text}" | |
node = xml.xpath_node("//*[contains(@class, 'main2')]") | |
node = node.xpath_node("*[contains(@class, 'cb')]") | |
puts "txt #{node.inner_text}" | |
puts "inner #{node.inner_text}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment