新手问题 可以抓取 Email 内容吗?

cqcn1991 · 2015年05月27日 · 最后由 cqcn1991 回复于 2015年05月27日 · 2152 次阅读

最近想爬虫抓一下 andrew chen 的博客 http://andrewchen.co/recent/ 页面上都有,唯一的问题就是没有日期... 想试试邮件订阅,然后从邮箱来试试抓一下内容,通过发送日期得到每篇的时间

可以,找一下 POP3 的实现就行了,比如 Ruby 内置的: http://ruby-doc.org/stdlib-2.1.0/libdoc/net/pop/rdoc/Net/POP3.html

require 'net/pop'

pop = Net::POP3.new('pop.example.com')
pop.start('YourAccount', 'YourPassword')             # (1)
if pop.mails.empty?
  puts 'No mail.'
else
  i = 0
  pop.each_mail do |m|   # or "pop.mails.each ..."   # (2)
    File.open("inbox/#{i}", 'w') do |f|
      f.write m.pop
    end
    m.delete
    i += 1
  end
  puts "#{pop.mails.size} mails popped."
end
pop.finish                                           # (3)
  1. Call #start and start POP session.
  2. Access messages by using #each_mail and/or #mails.
  3. Close POP session by calling #finish or use the block form of start.

如果要找第三方库,或许这个可以考虑: https://github.com/mikel/mail#getting-emails-from-a-pop-server

还可以通过 RSS 来得到时间。http://andrewchen.co/feed/

#3 楼 @tzwm 晕死,我开始找 RSS 半天没找到。。。。你怎么一下找到了了。。。

#4 楼 @cqcn1991 楼主你知道 rss 在哪里找吧?在源码的 header 里面找 application/rss

#5 楼 @blacktulip 真不知道…我一直以为是有个 rss 链接的哈哈哈哈

需要 登录 后方可回复, 如果你还没有账号请 注册新账号