Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 使用从另一个站点收集的内容填充Rails应用程序_Ruby On Rails - Fatal编程技术网

Ruby on rails 使用从另一个站点收集的内容填充Rails应用程序

Ruby on rails 使用从另一个站点收集的内容填充Rails应用程序,ruby-on-rails,Ruby On Rails,我需要种子或刮从另一个网站的数据,以有我的项目的内容 您如何使用自己的rails应用程序从另一个站点抓取数据?您是否使用单独的应用程序/服务器来运行某种cron作业,然后将该数据添加到rails应用程序中?或者,是否有可能让您自己的网站刮取数据并直接显示 我的第一个想法是使用Mechanize刮取一个站点,然后将数据作为种子数据添加到rails应用程序中的装置中。有更好的办法吗?甚至可能是一种使用我自己的rails应用程序不断刮取其他站点以显示数据的方法?我使用heroku,它附带了一个名为sc

我需要种子或刮从另一个网站的数据,以有我的项目的内容

您如何使用自己的rails应用程序从另一个站点抓取数据?您是否使用单独的应用程序/服务器来运行某种cron作业,然后将该数据添加到rails应用程序中?或者,是否有可能让您自己的网站刮取数据并直接显示


我的第一个想法是使用Mechanize刮取一个站点,然后将数据作为种子数据添加到rails应用程序中的装置中。有更好的办法吗?甚至可能是一种使用我自己的rails应用程序不断刮取其他站点以显示数据的方法?

我使用heroku,它附带了一个名为scheduler的东西,它对我的小项目非常有效。我相信它的工作原理与cron非常相似

一旦数据被废弃。它直接进入数据库(psql),然后您可以通过数据库查询显示您想要的任何内容

您不需要单独的应用程序。您可以在模型中使用一些方法来处理数据库的所有刮取和填充,然后您可以创建一个rake文件来运行这些函数

我把我的名字命名为.rake

这在/lib/tasks中/

然后,如果您使用Heroku,您将能够添加调度程序插件(2018年12月28日免费提供)


Heroku很好地解释了如何在Heroku方面进行配置。

您可以使用rufus scheduler和watir dom wait gem来解决问题。我还为amazon kdp图书列表抓取做了类似的任务 通过使用watirdomwait gem,您还可以为ajax调用请求获取数据,mechanize和Nokogiri不适用于ajax

require 'rufus-scheduler'
require 'watir-dom-wait'
require 'selenium-webdriver'
scheduler = Rufus::Scheduler.new

scheduler.in '1d' do
  download_report
end
#download the report form amazon kdp
def download_report
  #login
  @browser = Watir::Browser.new :chrome, options: {prefs: prefs}
  @browser.goto 'https://kdp.amazon.com/en_US/reports-new'
  @browser.input(:name => "email").send_keys("test@gmail.com")
  @browser.input(:name => "password").send_keys("password")
  @browser.input(:id => 'signInSubmit').click
  @browser.span(:text => "Generate Report").click
end

@艾丽,请核对我的答案,我要的是什么