【问题标题】:Joining two HTML scripts together将两个 HTML 脚本连接在一起
【发布时间】:2016-08-02 04:36:58
【问题描述】:

几乎相同的 HTML 脚本,每个都由 Powershell 脚本生成,并创建一个 .html 输出到本地驱动器。输出是在服务器上进行一些查询之后的结果表。

每个 HTML 输出文件都会按预期打开一个格式,但是,我希望将两个输出文件合并到一个脚本中,该脚本将作为单个 HTML 消息输入电子邮件。请原谅粗略的格式 - 为了简单起见,我已从脚本中删除了样式。

这是脚本 1,在 Powershell 中称为 $Table1:

<html> 
  <head> 
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
     <title>App Report</title> 
  </head> 

  <body> 
     <font face='calibri' color='#003399' size='4'><strong>App Server Report</strong></font> 
  </td>
  </tr> 
  </table> 

 <table width='auto'><tbody> 
 <td width='auto' bgcolor='#d98880'' align='center'>Server</td>
 <td width='auto' bgcolor='#a9dfbf'' align='center'>Service</td> 
 </tr> 
      <tr> 
      <td width='auto'>Server1</td> 
      <td width='auto' align='center'>Running</td>
      </tr> 
 </tr>  

这是 Script1 的输出,称为 $Table2:

...这里是脚本 2:

<html> 
      <head> 
        <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
         <title>Web Report</title> 

      </head> 

<body> 
      <font face='calibri' color='#003399' size='4'><strong>Web Server Report</strong></font> 
      </td> 
      </tr> 
      </table> 

     <table width='auto'><tbody> 
     <td width='auto' bgcolor='#d98880'' align='center'>Server</td>
     <td width='auto' bgcolor='#aed6f1'' align='center'>Apache Service</td>  
     <td width='auto' bgcolor='#aed6f1'' align='center'>WWW Service</td>
     <td width='auto' bgcolor='#aed6f1'' align='center'>WAS Service</td>
     </tr>
     <tr> 
          <td width='auto'>SERVER2</td>  
          <td width='auto' align='center'>Running</td>
          <td width='auto' align='center'>Running</td>
          <td width='auto' align='center'>Running</td>
          </tr>
    </tr>   

这是格式化的输出:

所以现在在我的 PS 脚本中,我将这两个都放入了 HTML 变量中:

$HTMLmessage = @"
$Table1
$Table2
"@

但是 $Table2 的标题嵌套在前一个表的最后一个 td 中。我知道必须有正确的方法来做到这一点 - 我不懂 HTML,但我们将不胜感激。

谢谢

【问题讨论】:

标签: html powershell


【解决方案1】:

我主要看到两个问题:

首先:你不能有2个&lt;html&gt;&lt;body&gt;标签,所以基本上你必须从$table2中删掉

第二个:有很多未打开或未关闭的标签。

第一个脚本的输出必须是:

<html> 
  <head> 
    <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> 
     <title>App Report</title> 
  </head> 

  <body> 
     <font face='calibri' color='#003399' size='4'><strong>App Server Report</strong></font> 


 <table width='auto'>
<tr> 
 <td width='auto' bgcolor='#d98880'' align='center'>Server</td>
 <td width='auto' bgcolor='#a9dfbf'' align='center'>Service</td> 
 </tr> 
      <tr> 
      <td width='auto'>Server1</td> 
      <td width='auto' align='center'>Running</td>
      </tr> 
 </tr> 
</table>

第二个

     <font face='calibri' color='#003399' size='4'><strong>Web Server Report</strong></font> 


     <table width='auto'><tr> 
     <td width='auto' bgcolor='#d98880'' align='center'>Server</td>
     <td width='auto' bgcolor='#aed6f1'' align='center'>Apache Service</td>  
     <td width='auto' bgcolor='#aed6f1'' align='center'>WWW Service</td>
     <td width='auto' bgcolor='#aed6f1'' align='center'>WAS Service</td>
     </tr>
     <tr> 
          <td width='auto'>SERVER2</td>  
          <td width='auto' align='center'>Running</td>
          <td width='auto' align='center'>Running</td>
          <td width='auto' align='center'>Running</td>
          </tr>
    </tr>   
</table>
</body>
</html>

(如果您想添加一些其他输出,请省略 /body/html

现在您可以选择如何解析输出以操作替换或修复脚本以获得格式良好的 HTML

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-28
    • 2021-03-15
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    相关资源
    最近更新 更多