繁体   English   中英

Ruby Rails和Webscraping(Nokogiri)和Nitrous.io

[英]Ruby Rails and Webscraping (Nokogiri) and Nitrous.io

我可以使用Rails和Nokogiri吗?

我尝试了此线程,并遇到了相同的问题,但是解决方案对我不起作用: 不能在Rails中要求“ nokogiri”(但在irb中有效)

 class IndexController < ApplicationController
 require 'nokogiri'
    require 'open-uri'
  def index
    @name = "Help"


    end

end

我得到的错误是:

cannot load such file -- nokogiri

我正在nitroous.io中运行它。 我使用以下方法列出了宝石:

 <li>Ruby: <%=RUBY_VERSION%></li>
 <li>Gems: <%=`gem list`%></li>

哪个让我

    Ruby: 2.0.0
Gems: actionmailer (4.0.0) actionpack (4.0.0) activemodel (4.0.0) activerecord (4.0.0) activerecord-deprecated_finders (1.0.3) activesupport (4.0.0) arel (4.0.0) atomic (1.1.14) builder (3.1.4) bundler (1.3.5) coffee-rails (4.0.0) coffee-script (2.2.0) coffee-script-source (1.6.3) erubis (2.7.0) execjs (2.0.1) hike (1.2.3) i18n (0.6.5) jbuilder (1.5.1) jquery-rails (3.0.4) json (1.8.0) mail (2.5.4) mime-types (1.25) minitest (4.7.5) multi_json (1.8.0) polyglot (0.3.3) rack (1.5.2) rack-test (0.6.2) rails (4.0.0) railties (4.0.0) rake (10.1.0) rdoc (3.12.2) sass (3.2.10) sass-rails (4.0.0) sdoc (0.3.20) sprockets (2.10.0) sprockets-rails (2.0.0) sqlite3 (1.3.8) thor (0.18.1) thread_safe (0.1.3) tilt (1.4.1) treetop (1.4.15) turbolinks (1.3.0) tzinfo (0.3.37) uglifier (2.2.1)

即使我已经运行了gem install nokogiri,Nokogiri也不在这里。

nokogiri添加到您的gem文件,运行bundle install并开始使用它。 无需require

安装捆绑软件后,您可以立即在控制器操作中使用它。 例如

def index
 p = Nokogori::HTML(open('http://domain.com')) #=> p now have the contents of the page
end

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM