• 用Ruby写的离线浏览代理服务器,重要更新


    安装完Ruby之后,doc目录里自带了一本书《THE BOOK OF RUBY》,粗看还可以,细看就一般了,而且是基于ruby 1.8的。Ruby 1.9改了很多地方,跟1.8不完全兼容了,改掉了一些缺点,很不错。最近在上一篇博客的基础上又做了以下改进:

    1.个别网页中有编码错误的字符,不能正确解析,用下面的代码加以修正。

    1if not text.valid_encoding?
    2  puts "warnig: text contains invalid chars"
    3  text.encode!("utf-8", :invalid => :replace, :replace => ".").encode!(text.encoding)
    4end
    

    2.网页内容压缩后再存入数据库,有效地减小了数据体积。

     1module Gzip
     2  require 'zlib'
     3  def Gzip.compress(text)
     4    stream = StringIO.new
     5    stream.set_encoding("ASCII-8BIT")
     6    gzip = Zlib::GzipWriter.new(stream)
     7    gzip.write text
     8    gzip.close
     9    stream.string
    10  end
    11
    12  def Gzip.decompress(data, encoding = "utf-8")
    13    stream = StringIO.new(data,"rb")
    14    gzip = Zlib::GzipReader.new(stream)
    15    text = gzip.read
    16    gzip.close
    17    text.force_encoding(encoding)
    18    text
    19  end
    20end
    

    3.看了就知道,此处不说了。

    4.为了方便使用,我把自己的服务器贡献出来了,不需要安装任何文件,只要在浏览器中把代理服务器设置成116.255.235.62:9999,然后打开cnbeta里面24小时以前的文章就可以看到效果了。

  • 相关阅读:
    java_IO流之 NIO
    No enclosing instance of type Outer is accessible. Must qualify the allocation with an enclosing instance of type Outer (e.g. x.new A() where x is an instance of Outer)
    JAVA I/O流 之入门
    10年老司机经验总结--程序员兼职的那些事
    python 去除html 超链接href 如何实现?
    《模式分类(原书第二版)》pdf格式下载电子书免费下载
    通知-招财猫问题通知专用
    Centos6.5 安装 python3.5 虚拟环境 virtualenvwrapper
    5.区块链平台以太坊从入门到精通之 以太网区块链网络
    4.区块链平台以太坊从入门到精通之 以太币
  • 原文地址:https://www.cnblogs.com/rufi/p/2740824.html
Copyright © 2020-2023  润新知