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

tim_lang · 2015年02月13日 · 最后由 luikore 回复于 2015年02月13日 · 1817 次阅读

例如:中国, 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"
需要 登录 后方可回复, 如果你还没有账号请 注册新账号