This is probably pretty basic stuff, but I can't seem to manage to get
my head 'round it:
I'm going through a number of webpages using mechanize. It is a
database, with many pages and 10 links on each page. I save the first 10
links into a txt file, continue to the next page, and save those 10.
Etcetera.
However, how do I determine it to to automatically stop when there is no
'next page' (link_with(:text => 'Next >') ?
# get all links on the page and save to txt file
pagina = agent.page
links = pagina.search("//td[@class = 'upper']/a")
open('pc1000.txt', 'a') { |f| f.puts links }
#open next page and save to textfile
agent.page.link_with(:text => 'Next >').click
open('pc1000.txt', 'a') { |f| f.puts links }
#etcetera, but how do make it loop and end untill there is no longer a
'Next >' link? to click ???!
This is probably pretty basic stuff, but I can't seem to manage to get
my head 'round it:
I'm going through a number of webpages using mechanize. It is a
database, with many pages and 10 links on each page. I save the first 10
links into a txt file, continue to the next page, and save those 10.
Etcetera.
However, how do I determine it to to automatically stop when there is no
'next page' (link_with(:text => 'Next >') ?
# get all links on the page and save to txt file
pagina = agent.page
links = pagina.search("//td[@class = 'upper']/a")
open('pc1000.txt', 'a') { |f| f.puts links }
#open next page and save to textfile
agent.page.link_with(:text => 'Next >').click
open('pc1000.txt', 'a') { |f| f.puts links }
#etcetera, but how do make it loop and end untill there is no longer a
'Next >' link? to click ???!