eval_in_page的问题-尝试插入数组 [英] Issue with eval_in_page - Trying to interpolate an array

查看:82
本文介绍了eval_in_page的问题-尝试插入数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

my @para_text = $mech->xpath('/html/body/form/table/tbody/tr[2]/td[3]/table/tbody/tr[2]/td/table/tbody/tr[3]/td/div/div/div', type => $mech->xpathResult('STRING_TYPE'));
#BELOW IS JUST TO MAKE SURE THE ABOVE CAPTURED THE CORRECT TEXT 
print "Look here: @para_text";

$mech->click_button( id => "lnkHdrreplyall");
$mech->eval_in_page('document.getElementsByName("txtbdy")[0].value = "@para_text"');

在我的代码的最后一行中,我需要将@para_text数组的内容作为文本输出到网站上的文本框中,但是从文档"到该行的末尾需要将其括起来通过"来工作.显然,这不允许插值,因为这需要"关于操作的任何想法?

In the last line of my code I need to put the contents of the @para_text array as the text to output into a text box on a website however from the "document" till the end of the line it needs to be surrounded by ' ' to work. Obviously this doesnt allow interpolation as that would require " " Any ideas on what to do?

推荐答案

要定义本身包含双引号以及对变量值进行插值的字符串,可以使用双引号qq/ ... /的替代形式,您可以在其中自己选择定界符,并防止双引号"特殊

To define a string that itself contains double quotes as well as interpolating variable values, you may use the alternative form of the double quote qq/ ... /, where you can choose the delimiter yourself and prevent the double quote " from being special

所以你可以写

$mech->eval_in_page(qq/document.getElementsByName("txtbdy")[0].value = "@para_text"/)

这篇关于eval_in_page的问题-尝试插入数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆