Skip to content

Instantly share code, notes, and snippets.

@ocean
Created October 15, 2009 10:54
Show Gist options
  • Save ocean/210889 to your computer and use it in GitHub Desktop.
Save ocean/210889 to your computer and use it in GitHub Desktop.
<h1>Feeds Checker</h1>
<%
require 'hpricot'
require 'open-uri'
f1 = open("http://www.commerce.wa.gov.au/feeds/feed1.xml")
feed = Hpricot.XML(f1)
#thing = (feed/:channel/:title).inner_html # works but returns *all* "title" tags, not just channel one.
feedTitle = feed.search("/rss/channel/title").innerHTML
feedItem = feed.search("rss/channel//item")
%>
<p>Here is some content I prepared earlier.</p>
<h3><%= feedTitle %></h3> <!-- This bit works! -->
<%
feedItem.each do |el|
title = el.search("title").first.inner_html
#url = el.search("link").first.inner_html
url = el.get_elements_by_tag_name("link").inner_html
desc = el.search("description").first.inner_html
output = "<p><a href='#{url}'>#{title}</a></p>"
puts output # This bit doesn't :-((((
end
%>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment