P
PP
In watir there is a function named links(). It returns a Links object .
I want to put a certain links of one web page into an array and visit
web pages by these links. My codes are as follows,the result sugguests
that the "a2[j]" stores something but not links. Can anyone help me to
check out the errors? Best regards
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
require'Watir'
ie=Watir::IE.new
ie.goto("www.baidu.com")
n=ie.links.length
puts n
$i=1
$j=1
$k=1
a1=Array.new #a1 is used to store all the links in the
#page
a2=Array.new #a2 is used to store the certain links
#that contains the string 'baidu'
while $i<=n
a1[$i]=ie.links[$i].to_s
if /(www.baidu.com)/.matches(a1[$i])
a2[$j]=ie.links[$i]
$j=$j+1
end
$i=$i+1
end
while a2[$k]
ie.goto(a2[$k])
ie.back
$k=$k+1
end
I want to put a certain links of one web page into an array and visit
web pages by these links. My codes are as follows,the result sugguests
that the "a2[j]" stores something but not links. Can anyone help me to
check out the errors? Best regards
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
require'Watir'
ie=Watir::IE.new
ie.goto("www.baidu.com")
n=ie.links.length
puts n
$i=1
$j=1
$k=1
a1=Array.new #a1 is used to store all the links in the
#page
a2=Array.new #a2 is used to store the certain links
#that contains the string 'baidu'
while $i<=n
a1[$i]=ie.links[$i].to_s
if /(www.baidu.com)/.matches(a1[$i])
a2[$j]=ie.links[$i]
$j=$j+1
end
$i=$i+1
end
while a2[$k]
ie.goto(a2[$k])
ie.back
$k=$k+1
end