我想在html文档中添加一个文本字符串。
我的网站有一个“更新”部分,你可以看到他们开车去了哪里。(这是一个为一些骑自行车的人准备的网站)
我想这样做,所以我爸爸只需要打开一个bat文件,输入一些信息,然后它就会将字符串添加到html文档中。
我目前使用一个“表”作为布局。
代码如下:
<tr style="mso-yfti-irow:34">
<td valign="top" style="width:180;padding-left:3.5pt; padding-light:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">DATE</font>
</td>
<td valign="top" style="width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">LOCATION</font></td>
<td valign="top" style="width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">AMOUNT</font>
</td>
</tr>
当前网站
<html>
<head>
Some things here....
</head>
<body>
<div>
More things here
</div>
<table>
the table/the place where new text should be added
</table>
A bit more
</body>
</html>
我正在做的事情是,我可以用下面的代码创建一个bat文件
echo off
set /p Date="Date: "
set /p Location="Location: "
set /p Amount="Amount: "
(some command here to add it)
<tr style="mso-yfti-irow:34">
<td valign="top" style="width:180;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">%Date%</font></td>
<td valign="top" style="width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">%Location%</font></td>
<td valign="top" style="width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">%Amount%</font></td>
</tr>
Exit
新文本应始终添加到表格的底部,但不能添加到html文档的底部
行nr。也将永远改变
我希望我已经解释得足够好了,如果你有什么不明白的地方,那就写下来,然后我会试着澄清
发布于 2018-08-11 08:07:23
听起来您已经编写了bat脚本来提示您的父亲输入值。因此,我将重点介绍如何将它们插入到您的html页面中。
在当前的html文件中,更改表格末尾的格式,将最后一个直接放在
</tr></table>
在bat文件中,替换
(some command here to add it)
<tr style="mso-yfti-irow:34">
<td valign="top" style="width:180;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">%Date%</font></td>
<td valign="top" style="width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">%Location%</font></td>
<td valign="top" style="width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5">
<font size="4">%Amount%</font></td>
</tr>
有了这个
powershell -command "(Get-Content Name_of_File.html) -replace '</tr></table>', '<tr style="mso-yfti-irow:34"> <td valign="top" style="width:180;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5"><font size="4">%Date%</font></td><td valign="top" style="width:500;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5"><font size="4">%Location%</font></td><td valign="top" style="width:523;padding-left:3.5pt; padding-right:3.5pt; padding-top:0cm; padding-bottom:0cm" height="5"><font size="4">%Amount%</font></td></tr></table>' | Set-Content Name_of_File.html"
Powershell.exe -executionpolicy remotesigned -File replace_quot.ps1
这将从批处理脚本中执行PowerShell搜索和替换命令,以查找新行并将其替换。每次你的父亲在页面上添加新的旅行时,它都会将信息添加到表格的底部。
powershell -command让批处理知道作为powershell执行“双引号”之间的所有内容。get-content读取您的html文件。因此,将Name_of_File.html替换为您的HTML页面的名称。
该命令的下一部分执行搜索和替换。您必须为powershell使用“替代”,才能将整行作为一组流畅的操作来读取。它将编写HTML代码,并使用您的变量%Date%、%Location%和%Amount%作为新值。
然后使用set-content将该文件写回到html页面。因此,请确保在此处也使用您的Name_of_File.html页面的名称更新了HTML。
将以下行保存在另一个名为replace_quot.ps1的脚本中,并将此脚本放在与bat文件相同的目录中。
(Get-Content Name_of_File.html) -replace '"', '"' | set-content Name_of_File.html
此脚本将被您的bat文件调用,以将&qout;替换为html文件中的实际“字符。
https://stackoverflow.com/questions/51792265
复制相似问题