InfoQ的自动新闻订阅

发现InfoQ的RSS很不厚道,只现实一个该要。想要知道详细内容的话不得不点进去看。如果用手机的话流量剧增。那么我就写了一个很简单的ruby代码,比如把InfoQ的和ruby相关的新闻提出来。每天晚上发到我的邮箱,那么我就不用理会网页上的那么多广告了。

发邮件部分就不贴了,就给一个大概的思路吧。主要是学习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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值