所以我使用 gem 文件从 reddit 的首页拉取链接。gem 函数返回一个哈希,其中包含首页上的所有链接及其所有信息(评论数、业力、作者、日期、链接、上升、下降等)。以下是包含我首页上第一个链接信息的哈希的乞求:
{"modhash"=>"ubekfji9tr491ba98806d33ec78693dc157579335eb1ab283b", "children"=>[{"kind"=>"t3", "data"=>{"domain"=>"i.imgur.com", "banned_by"=>无,“media_embed”=>{},“subreddit”=>“图片”,“selftext_html”=>无,“selftext”=>“”,“喜欢”=>无,“link_flair_text”=>无,“id "=>"1dt29e", "clicked"=>false, "title"=>"我们在意大利的水管工亲自出去找我们帮忙做他的英语作业 :) 希望他能通过他的期末考试!", "media" =>nil, "score"=>3700, "approved_by"=>nil, "over_18"=>false, "hidden"=>false,“缩略图”=>“ http://b.thumbs.redditmedia.com/Fdid4luCfXah0bQ7.jpg", "subreddit_id"=>"t5_2qh0u", "edited"=>false, "link_flair_css_class"=>nil, "author_flair_css_class"=>nil, "downs"=>17890, "saved"=>false, "is_self"= >false, "permalink"=>"/r/pics/comments/1dt29e/our_plumber_in_italy_put_himself_out_there_to_ask/", "name"=>"t3_1dt29e", "created"=>1367893951.0, "url"=>" http://i. imgur.com/3xn1c8s.jpg ", "author_flair_text"=>nil, "author"=>"Junpha", "created_utc"=>1367865151.0, "distinguished"=>nil, "num_comments"=>553, "num_reports"= >nil, "ups"=>21590}},
该结尾,
将下一个链接分开,如下所示:
{"kind"=>"t3", "data"=>{"domain"=>"i.imgur.com", "banned_by"=>nil, "media_embed"=>{}, "subreddit"=>"有趣的", "selftext_html"=>nil, "selftext"=>"", "likes"=>nil, "link_flair_text"=>nil, "id"=>"1dt4xv", "clicked"=>false, "title "=>"多么美丽,雄伟....哎呀", "media"=>nil, "score"=>2848, "approved_by"=>nil, "over_18"=>false, "hidden"=>false , "缩略图"=>" http://a.thumbs.redditmedia.com/vkstE1PFr9iyYpux.jpg ", "subreddit_id"=>"t5_2qh33", "edited"=>false,"link_flair_css_class"=>nil, "author_flair_css_class"=>nil, "downs"=>8128, "saved"=>false, "is_self"=>false, "permalink"=>"/r/funny/comments/1dt4xv/ what_a_beautiful_majestic_oops/", "name"=>"t3_1dt4xv", "created"=>1367895955.0, "url"=>" http://i.imgur.com/62q1jWN.gifgifgif", "author_flair_text"=>nil, "author"=>"themisc", "created_utc"=>1367867155.0, "distinguished"=>nil, "num_comments"=>279, "num_reports"=>nil, "ups"= >10976}},
我基本上需要某种方式来解析这个哈希的每个条目,以便我可以将所有相关的东西存储到一个数组中。真的,我只想将"title"
and"url"
部分存储到一个数组中。我试过这样的事情:
@red.get_listing().each do |x['title']|
puts x
end
但我意识到这是一个散列的散列..所以我对如何解析这个有点迷茫。