我正在编写一个应该获取页面源代码并显示它的应用程序。
它将是一种简单的 JSON 格式,没有 HTML 或 CSS。所以我试图获取的网站的源代码如下所示:
{"latitude" : "n/a","longitude" : "n/a","internalTemperature" : "n/a","light" : "n/a","distance" : "n/a" ...
每次使用 httparty,我都会得到这样的结果:
#, @headers={"x-frame-options"=>["sameorigin"], "x-xss-protection"=>["1; mode=block"], "content-type"=>["text/html;charset=utf-8"], "content-length"=>["86692"], "server"=>["WEBrick/1.3.1 (Ruby/1.9.2/2012-04-20)"], "date"=>["Wed, 09 May 2012 17:46:34 GMT"], "connection"=>["close"]}>
那是什么类型的数据?,我不明白。
我的 erb 文件中有这样一行:
<%= Representative.get('http://0.0.0.0:4568/').inspect %>
在我的 .rb 文件中:
class Representative
include HTTParty
end
显然,我要访问的站点在我的本地主机上,所以你看不到它,但它会返回一个简单的 JSON,就像我展示的那样。