my @para_text = (
"The build of $build CUT$cut was started as requested and
its progress can be monitored in Anthill here",
"",
"http://anthill:8080/tasks/project/BuildLifeTasks/viewBuildLife?
buildLifeId=$lifeid",
"",
'If it completes successfully (Overall Anthill status will show as green
Complete and all sub steps as green Success) the built output will be
available for deployment and testing by first copying the zip file from here
\\\mizar\release\AnthillRelease\$build',
"", "If the output exists but the anthill build was not completely
successful DO NOT attempt to copy and deploy the output. \n",
"We will send the usual email detailing content etc. when the build
finishes. \n");
$para_text[0] =~ s/[\r\n]//gm; # convert multiline to single line
@para_text = join "\n", @para_text;
s/([\\"])/\\$1/g, s/\n/\\n/g for @para_text;
$mech->eval_in_page( qq/document.getElementsByName("txtbdy")[0].value = "@para_text", "test"/ );我有上面的密码。
数组包含一个电子邮件模板,脚本是在Outlook周围使用WWW::Mechanize::Firefox制作的。
电子邮件模板中有一个目录,其中有反斜杠。
MozRepl在将文本放入$mech->eval_in_page行的文本框时不允许反斜杠或任何特殊字符。
如果模块不允许反斜杠,我如何在文本中放反斜杠?
发布于 2017-04-12 08:25:23
我从代码中删除了反斜杠,并在
$para_text[4] =~ s{!}{\\}g;问题解决了。在以后的作品中用一个字符代替反斜杠。
发布于 2017-04-12 15:35:27
看看这个答案。我不得不创建一个本地HTML文件,并假设您使用的是<textarea />,因为简单的<input type="text" />不接受多行
txtbdy.html
<html>
<head>
<title>Textbox test</title>
<style type="text/css">
#textbdy {
width: 800;
height: 300;
resize: none;
}
</style>
</head>
<body>
<form>
<textarea name="txtbdy" id="textbdy" />
</form>
<body>
</html>这里我使用了您问题中的数据,除了复制$para_text[4]来修复$build的插值和测试双引号(围绕"Athill")。
txtbdy.pl
use utf8;
use strict;
use warnings 'all';
use WWW::Mechanize::Firefox;
my $mech = WWW::Mechanize::Firefox->new(
tab => qr/Textbox test/,
create => 1,
activate => 1,
);
$mech->autoclose_tab( 0 );
$mech->get( 'file://E:/Perl/source/txtbdy.html' );
my $build = "BUILD";
my $cut = "CUT";
my $lifeid = "LIFEID";
my @para_text = (
"The build of $build CUT$cut was started as requested and
its progress can be monitored in Anthill here",
"",
"http://anthill:8080/tasks/project/BuildLifeTasks/viewBuildLife?
buildLifeId=$lifeid",
"",
'If it completes successfully (Overall Anthill status will show as green
Complete and all sub steps as green Success) the built output will be
available for deployment and testing by first copying the zip file from here
\\\mizar\release\AnthillRelease\$build',
"",
qq{If it completes successfully (Overall "Anthill" status will show as green
Complete and all sub steps as green Success) the built output will be
available for deployment and testing by first copying the zip file from here
\\\\mizar\\release\\AnthillRelease\\$build},
"",
"If the output exists but the anthill build was not completely
successful DO NOT attempt to copy and deploy the output. \n",
"We will send the usual email detailing content etc. when the build
finishes. \n"
);
my $para_text = join "\n", @para_text;
s/([\\"])/\\$1/g, s/\n/\\r\\n/g for $para_text;
$mech->eval_in_page( qq/document.getElementsByName("txtbdy")[0].value = "$para_text"/ );输出
此输出正确地表示“尴尬”字符换行符和双引号,这将使JavaScript字符串的语法失效。它使用了与我在对前面的问题https://stackoverflow.com/questions/43142971的评论中所建议的完全相同的替换。
s/([\\"])/\\$1/g, s/\n/\\n/g for @para_text;

https://stackoverflow.com/questions/43320347
复制相似问题