-
-
Save ezefranca/2fd80a576179e6fde759ea5870a56ea3 to your computer and use it in GitHub Desktop.
testing nokogiri
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' | |
html = ' | |
<html> | |
<body> | |
<p>foo banana 1</p> | |
this text | |
<p>bar</p> | |
<p>foo banana 2</p> | |
<p>foo banana 3</p> | |
<p> else </p> | |
<p> foo </p> | |
<p> foo </p> | |
<p> foo </p> | |
</body> | |
</html> | |
' | |
keywords = ["else", "banana", "nomatch"] | |
doc = Nokogiri::HTML(html) | |
total_matches = 0 | |
keywords.each do |keyword| | |
p "searching for:"+keyword | |
elements = doc.search('p:contains("'+keyword+'")') | |
if(elements) | |
elements.each do |element| | |
total_matches=total_matches+1 | |
p element.text | |
end | |
else | |
p "NO MEANS NO!" | |
end | |
p "============" | |
end | |
p "total matches for keywords:" + total_matches.to_s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment