C
curious
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.
Thanks.
=====================================================================
require 'watir'
ie = Watir::IE.start("http://www.test.com")
file = File.open("c:/items.txt", "r")
lines = file.readlines()
PageNo = 1
0.upto(lines.length - 1) {|j|
$item = lines[j]
ie.text_fieldname, "item").value = $item
ie.buttonname, "Search").click
a = ie.contains_text("Next")
while a
File.open("#{PageNo}.html", "wb") { |f|
f << '<html>'
f << ie.html
f << '</html>'
PageNo = PageNo + 1
ie.linktext, "Next").click
}
end
}
file.close()
lines.clear()
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.
Thanks.
=====================================================================
require 'watir'
ie = Watir::IE.start("http://www.test.com")
file = File.open("c:/items.txt", "r")
lines = file.readlines()
PageNo = 1
0.upto(lines.length - 1) {|j|
$item = lines[j]
ie.text_fieldname, "item").value = $item
ie.buttonname, "Search").click
a = ie.contains_text("Next")
while a
File.open("#{PageNo}.html", "wb") { |f|
f << '<html>'
f << ie.html
f << '</html>'
PageNo = PageNo + 1
ie.linktext, "Next").click
}
end
}
file.close()
lines.clear()