my $V1 = $sel->get_text("//body[\@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/div/table/tbody/tr/td/div/div");
print($V1 . "\n");
当我执行上述命令时,我可以无误地打印v1。
我的目标是打印这些值(比如20左右)。但每个变量的xpath仅因div
元素而异(即div
元素先行table
应替换为div[2],
,而div[2]
应替换为div[3]
每次迭代都会{1}}。
以下代码段执行替换div []元素。但是说xpath无效。
my $xpath = q(//body[\@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/div/table/tbody/tr/td/div/div);
for my $i (0,2)
{
my @nodes = split qr'/', $xpath;
$nodes[16] .= "[$i]" unless 0 == $i;
#say join '/', @nodes; }
my @somenames = join('/',@nodes);
#print "\n";
#print @somenames ;
foreach my $val (@somenames) {
chomp($val);
#my @new_arr = $sel->get_text($val);
print "\n";
print $val; ***this prints the xpath value which i needed***
my $V1 = $sel->get_text("$val"); ***#i'm passing the same xpath here within double quotes but says as invalid xpath***
print($V1 . "\n");
my @new_arr = $sel->get_text("$val");
}
}
我是否遵循错误的传递xpath的方式?我该怎么办?