Ruby on rails 如何使用mechanize和ruby在循环中创建日志文件

Ruby on rails 如何使用mechanize和ruby在循环中创建日志文件,ruby-on-rails,ruby,mechanize,Ruby On Rails,Ruby,Mechanize,我试图在localhost上创建多个日志文件 其中一个文件是sign_in.rb 第二个是profile_page.rb 我如何组合这两个文件并在循环中运行它们以创建多个日志文件我对Mechanize不太了解,但是有什么原因不能简单地组合两个代码位并将它们放入while循环?我不知道你需要多久做一次Mechanize.new。要生成多个日志文件,只需打开两个不同的文件并写入即可 require 'mechanize' require_relative 'sign_in' log1 = File

我试图在localhost上创建多个日志文件

其中一个文件是sign_in.rb

第二个是profile_page.rb


我如何组合这两个文件并在循环中运行它们以创建多个日志文件

我对Mechanize不太了解,但是有什么原因不能简单地组合两个代码位并将它们放入while循环?我不知道你需要多久做一次Mechanize.new。要生成多个日志文件,只需打开两个不同的文件并写入即可

require 'mechanize'
require_relative 'sign_in'

log1 = File.open("first.log", "w")
log2 = File.open("second.log", "w")

@agent = Mechanize.new
while true
    # @agent = Mechanize.new  # not sure if this is needed
    page = @agent.get('http://localhost:3000/users/sign_in')
    form = page.forms.first
    form["user[username]"] ='admin'
    form["user[password]"]= '123456'
    @agent.submit(form,form.buttons.first)
    PP.pp page, log1

    # @agent = Mechanize.new  # not sure if this is needed
    page = @agent.get('http://localhost:3000/users/admin')
    form = page.forms.first
    form.radiobuttons_with(:name => 'read_permission_level')[1].check
    @agent.submit(form,form.buttons.first)
    PP.pp page, log2
end

如果您告诉我们您尝试了什么以及尝试时出现了哪些错误,这将是一个更好的问题!我有两个以上的文件,我想创建一个日志文件,该文件将合并所有文件并在循环中运行,是否有方法将文件生成类并在合并它们的文件中调用类。。谢谢你的帮助……对不起,我不明白你现在在问什么。创建一个日志文件来合并所有文件并在循环中运行是什么意思?日志文件不会合并或运行任何内容。日志文件不可执行。日志文件不运行或没有循环。也许你应该问一个新问题,或者对这个问题进行大量修改。
require 'mechanize'
require_relative 'sign_in'


page = @agent.get('http://localhost:3000/users/admin')
form =page.forms.first

form.radiobuttons_with(:name => 'read_permission_level')[1].check
@agent.submit(form,form.buttons.first)


pp page
require 'mechanize'
require_relative 'sign_in'

log1 = File.open("first.log", "w")
log2 = File.open("second.log", "w")

@agent = Mechanize.new
while true
    # @agent = Mechanize.new  # not sure if this is needed
    page = @agent.get('http://localhost:3000/users/sign_in')
    form = page.forms.first
    form["user[username]"] ='admin'
    form["user[password]"]= '123456'
    @agent.submit(form,form.buttons.first)
    PP.pp page, log1

    # @agent = Mechanize.new  # not sure if this is needed
    page = @agent.get('http://localhost:3000/users/admin')
    form = page.forms.first
    form.radiobuttons_with(:name => 'read_permission_level')[1].check
    @agent.submit(form,form.buttons.first)
    PP.pp page, log2
end