发现InfoQ的RSS很不厚道,只现实一个该要。想要知道详细内容的话不得不点进去看。如果用手机的话流量剧增。那么我就写了一个很简单的ruby代码,比如把InfoQ的和ruby相关的新闻提出来。每天晚上发到我的邮箱,那么我就不用理会网页上的那么多广告了。
发邮件部分就不贴了,就给一个大概的思路吧。主要是学习hpricot。在RSS方面javaeye做的很好。
发邮件部分就不贴了,就给一个大概的思路吧。主要是学习hpricot。在RSS方面javaeye做的很好。
require "rubygems"
require 'hpricot'
require 'open-uri'
HOST_NAME="http://www.infoq.com"
doc = Hpricot(open("http://www.infoq.com/cn/ruby"))
p = doc.search("//h1/a")
result = []
p.each do |pitem|
href = pitem.get_attribute("href")
title = pitem.search("//text()")
result << [title, href] if href =~ /\/cn\//
end
result.each do |items|
doc = Hpricot(open(HOST_NAME + items[1]))
# puts items[0]
doc.search("//div[@class='box-content-5']//p[@class='h1-r']").remove
doc.search("//div[@class='box-content-5']//p[@class='info']").remove
doc.search("//div[@class='box-content-5']//dl").remove
doc.search("//div[@class='box-content-5']//div[@class='vendor-content-box-float']").remove
doc.search("//div[@class='box-content-5']//div[@class='vendor-content-box']").remove
doc.search("//div[@class='box-content-5']//div[@class='comments-header']").remove
doc.search("//div[@class='box-content-5']//div[@class='forum-list-tree']").remove
doc.search("//div[@class='box-content-5']//div[@class='comments-sort']").remove
doc.search("//div[@class='box-content-5']//ol").remove
doc.search("//div[@class='box-content-5']//script").remove
doc.search("//div[@class='box-content-5']//br").remove
doc.search("//div[@class='box-content-5']//text()") do |item|
puts item
end
puts "_______________________________________________________________________\n\n"
end