From: Paul Lutus Date: 2006-12-05T17:55:08+09:00 Subject: Re: looping through & downloading web page - WATIR codes curious wrote: > What I am trying to realize through code below is to read a line by > line in items.txt, and download each ensuing pages by having WATIR > click 'Next' link. > > Now what I wish this code to do is when WATIR reaches the last page, > and there is no more "Next" link on the page, then go to the second > line in items.txt, searching again, and download ensuing pages again. > > But unfortunately, the WATIR code close down when there is no more > "Next" link on the first item search.. and it does not go to searching > with the second line in items.txt. > > Could anybody help me how I should adjust the code below so that when > there is no more "Next" link on the page, then the second line in > items.txt goes into searching, download each page by clicking "Next" > link.. on and on?? > > any suggestion will be deeply appreciated. Rather than simply rewriting your code for you, I offer these suggestions: 1. Always close the opened file handle when the write is completed. You are not closing your file handles until the last file is read, which in the worst case leaves many file handles open and abandoned. 2. Instead of doing this: 0.upto(lines.length - 1) {|j| $item = lines[j] Do it this way: lines.each do |item| # ... your code here end 3. Avoid use of global variables when possible. I would offer more suggestions but I don't actually understand what your program is meant to accomplish. -- Paul Lutus http://www.arachnoid.com