while 循环和机械化问题 Ruby

Troubles with while loop and mechanize Ruby

我不明白为什么我的 ruby 代码不能使用 while 和 mechanize。

require 'mechanize'
mechanize = Mechanize.new
j = 1
while j <= 30 do
    page = mechanize.get('http://mywebsite.com/events?page=#{j}'); j+=1
    i = 1
    while i <= 35 do
        link = page.link_with(:id => /detail-link-#{i}/); i += 1
        mylink = link.click
        url = mylink.uri
        title = mechanize.get(url)
        puts title.at('.container h1')
    end
end

我的while循环i可以,但是循环j没有进入下一页,我觉得我的逻辑不好,但我不知道问题出在哪里。

您尝试将页码插入页面的 URL。但插值仅适用于双引号 (").

改变

page = mechanize.get('http://mywebsite.com/events?page=#{j}'); j+=1

page = mechanize.get("http://mywebsite.com/events?page=#{j}"); j+=1