我正在编写一个应用程序,该应用程序使用大部分填写的 HTML 模板,并使用 nodemailer 发送电子邮件。我需要根据我的 webscraper 发生的情况在特定点写入静态 html 文件。
该节点有一个 id 属性,我称之为“root”或“insert_root”。
... MORE HTML ...
<tbody>
<tr>
<td class="pc-fb-font" style="padding: 20px 20px; text-align: center; font-...
<div id="insert_root" style="margin-left: 20px">
**Insert Here**
</div>
</td>
</tr>
</tbody>
... THE REST OF THE HTML ...
这样做的最简单和最可靠的方法是什么?我要插入的 html 内容如下所示:
<p style="margin-bottom: 10px; margin-left: 20px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 600; line-height: 1.42; letter-spacing: -0.4px; color: #151515;">Coons, Christopher A:</p>
<ul style="margin-left: 20px; margin-top: 0px; padding: 0px; ">
<li style="margin-left: 20px; font-family: Helvetica, Arial, sans-serif; font-size: 12px; font-weight: 500; line-height: 1.42; letter-spacing: -0.4px; color: #151515;"><a href=https://efdsearch.senate.gov/search/view/ptr/f06ca66b-6f1d-461e-990d-01e6bb206b51/>Periodic Transaction Report for 06/24/2019</a></li>
</ul>
<p style="margin-bottom: 10px; margin-left: 20px; font-family: Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 600; line-height: 1.42; letter-spacing: -0.4px; color: #151515;">Roberts, Pat:</p>
<ul style="margin-left: 20px; margin-top: 0px; padding: 0px; ">
<li style="margin-left: 20px; font-family: Helvetica, Arial, sans-serif; font-size: 12px; font-weight: 500; line-height: 1.42; letter-spacing: -0.4px; color: #151515;"><a href=https://efdsearch.senate.gov/search/view/annual/ea3ce82e-f1e0-4f16-8498-79d02398f06c/>Annual Report for CY 2018</a></li>
</ul>
我想我可以做一些事情,我使用 fs.readFile 读取文件并写入它,但想知道是否有更简单的解决方案涉及 Cheerio 或其他 HTML 解析器来获取确切的根节点,并以某种方式从那里插入.. .想法?