作者mgdesigner (魔法设计师)
看板Ruby
标题[问题] URI解译错误
时间Thu Feb 21 17:31:56 2008
(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)
1F:→ mgdesigner:是因为URL里面有棒子的关系吗?@_@ 02/21 18:11
2F:→ contagious:用 URI.escape 先过一次 02/22 00:16
3F:→ mgdesigner:多谢 02/26 15:39