如何使用废料宝石获取网址和宝石

时间:2014-06-05 09:36:06

标签: ruby-on-rails

我是ruby on rails的新手。我想从电子商务网站获取网址,图片,标题和价格如何使用此scrapify gem。能否请你详细说明。

https://github.com/tiagopog/scrapifier

中给出的文档中有点令人困惑

提前致谢

3 个答案:

答案 0 :(得分:0)

没有什么可以与其使用相混淆。您只需要将网站的 required url 作为 string 传递。例如

'http://adtangerine.com'.scrapify
#=> {
#   title:       "AdTangerine | Advertising Platform for Social Media",
#   description: "AdTangerine is an advertising platform that uses the tangerine as a virtual currency for advertisers and publishers in order to share content on social networks.",
#   images:      ["http://adtangerine.com/assets/logo_adt_og.png", "http://adtangerine.com/assets/logo_adt_og.png", "http://s3-us-west-2.amazonaws.com/adtangerine-prod/users/avatars/000/000/834/thumb/275747_1118382211_1929809351_n.jpg", "http://adtangerine.com/assets/foobar.gif"],
#   uri:         "http://adtangerine.com"
# }

与文档中的内容一样,您可以 choose 您想要的 scraped 这样的网址

'http://adtangerine.com and www.twitflink.com'.scrapify(which: 1)
#=> {
#   title:       "TwitFlink | Find a link!",
#   description: "TwitFlink is a very simple searching tool that allows people to find out links tweeted by any user from Twitter.",
#   images:      ["http://www.twitflink.com//assets/tf_logo.png", "http://twitflink.com/assets/tf_logo.png"],
#   uri:         "http://www.twitflink.com"
# }

'http://adtangerine.com and www.twitflink.com'.scrapify(which: 0)
#=> {
#   title:       "AdTangerine | Advertising Platform for Social Media",
#   description: "AdTangerine is an advertising platform that uses the tangerine as a virtual currency for advertisers and publishers in order to share content on social networks.",
#   images:      ["http://adtangerine.com/assets/foobar.gif"],
#   uri:         "http://adtangerine.com"
# }

注意:示例是从其文档中复制的。

答案 1 :(得分:0)

这样做 gem install scrapifier

然后通过Irb控制台执行这些

require 'scrapifier'

OutPut应该是

 => true 

然后

'http://adtangerine.com and www.twitflink.com'.scrapify(which: 0)

OutPut应该是

 => {:uri=>"http://adtangerine.com", :title=>"AdTangerine | We're experiencing problems with our servers.", :description=>"Hey there! Our web app will be back very soon, hold on just a little bit more :-)", :images=>[]} 

简单足够!!

  • 你正在做require 'scrapify'或不做?

答案 2 :(得分:0)

使用以下代码测试。示例代码.URL必须有效,否则使用条件

require 'open-uri' # already part of your ruby install
require 'scrapifier'

puts 'Wow! What an awesome site: http://petspinboard.com'.scrapify