[問題] URI解譯錯誤

看板Ruby作者 (魔法設計師)時間16年前 (2008/02/21 17:31), 編輯推噓0(003)
留言3則, 2人參與, 最新討論串1/1
(ctrl + y 刪去不必要的行列) 環境: Ruby 1.8.5 狀況: e.g. 我想要 XX, 結果 YY 程式在 ZZ 的地方有錯誤 我想要取得wikipedia的xml來解析,做進一步處理,於是寫了這一段 url = "http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvlimit=5&rvpro p=timestamp|user|comment&titles=computer" xml_data = Net::HTTP.get_response(URI.parse(url)).body 但是執行的時候,會有以下的錯誤: /usr/lib/ruby/1.8/uri/common.rb:432:in `split': bad URI(is not URI?): http://en.wikipedia.org/w/api.php?action=query&prop=revisions&rvlimit=5&rvprop =timestamp|user|comment&titles=computer (URI::InvalidURIError) 附錄: 我使用了以下類別 require 'net/http' require 'rexml/document' -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.56.157.129 ※ 編輯: mgdesigner 來自: 61.56.157.129 (02/21 17:33)

02/21 18:11, , 1F
是因為URL裏面有棒子的關係嗎?@_@
02/21 18:11, 1F

02/22 00:16, , 2F
用 URI.escape 先過一次
02/22 00:16, 2F

02/26 15:39, , 3F
多謝
02/26 15:39, 3F
文章代碼(AID): #17lKKFFZ (Ruby)