pldlt pldlt - 1 year ago 99
Ruby Question

Troubles with while loop and mechanize Ruby

I don't understand why my ruby code doesn't work with while and mechanize.

require 'mechanize'
mechanize =
j = 1
while j <= 30 do
page = mechanize.get('{j}'); j+=1
i = 1
while i <= 35 do
link = page.link_with(:id => /detail-link-#{i}/); i += 1
mylink =
url = mylink.uri
title = mechanize.get(url)
puts'.container h1')

My while loop
work but loop
doesn't go to the next page, I think my logic is not good but I don't know where the problem is.

Answer Source

You try to interpolate the page number into the page's URL. But interpolation only works with double quotes (").


page = mechanize.get('{j}'); j+=1


page = mechanize.get("{j}"); j+=1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download