Ruby 想抓取某台湾网站的数据,但是提交查询的时候是按 big5 来对 url 进行编码的

tim_lang · February 13, 2015 · Last by luikore replied at February 13, 2015 · 1823 hits

例如:中国, escape 后是%A4%A4%26%2322269%3B 而不是 encodeURIComponent('中国') => '%E4%B8%AD%E5%9B%BD', 如何处理。

首先 big5 是没有简体字的... 先装个简繁转换

gem ins ropencc

然后

require 'ropencc'
URI.escape Ropencc.conv('s2t.json', '中国').encode('big5') #=> "%A4%A4%B0%EA"
You need to Sign in before reply, if you don't have an account, please Sign up first.