Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在不影响使用Nodejs或Javascript的HTML标记的情况下从HTML中获取100到200个单词?_Javascript_Node.js - Fatal编程技术网

如何在不影响使用Nodejs或Javascript的HTML标记的情况下从HTML中获取100到200个单词?

如何在不影响使用Nodejs或Javascript的HTML标记的情况下从HTML中获取100到200个单词?,javascript,node.js,Javascript,Node.js,我从数据库中获取数据并发送邮件,数据带有HTML标记。现在的问题是我只想在邮件中显示100封信。但当我删除一些单词时,HTML标记也会删除,它会破坏整个输出。请指导我如何才能做到这一点 来自数据库的样本输出 <table border="0" cellspacing="0" cellpadding="0"> <tbody> <tr> <td class="snip">W

我从数据库中获取数据并发送邮件,数据带有HTML标记。现在的问题是我只想在邮件中显示100封信。但当我删除一些单词时,HTML标记也会删除,它会破坏整个输出。请指导我如何才能做到这一点

来自数据库的样本输出

<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="snip">We are looking for physically fit individuals to fill general labour requirements by partnering with a truck driver. Your help is needed to load/unload the truck at the various job sites.
<b>Skills required: </b>
- comfortable with physical exertion and lifting minimum of 50lbs
- works well on a team but trusted to work independently
- reliable, self-motivated and committed to high standards of quality
- able to read and understand work instructions
<b>Specific requirements: </b>
- in good physical condition
- must have own safety footwear
- reliable transportation to ensure punctual and consistent attendance
If you meet the qualifications listed above, submit your resume in MS Word format via the link below.
<i>Previously employed with The Staffing Connection? Please contact our office to confirm your continued availability for these upcoming positions.</i></td>
</tr>
</tbody>
</table>

我们正在寻找身体健康的个人,通过与卡车司机合作来满足一般劳动要求。需要您的帮助才能在各个工作现场装卸卡车。
所需技能:
-舒适的体力消耗和最低50磅的举重
-在团队中工作良好,但可以独立工作
-可靠,自我激励,致力于高质量标准
-能够阅读和理解工作说明
具体要求:
-身体状况良好
-必须有自己的安全鞋
-可靠的交通,确保准时和一致的出勤
如果您符合上述资格,请通过以下链接以MS Word格式提交您的简历。
以前受雇于员工关系?请联系我们的办公室,确认您是否能继续胜任这些即将到来的职位。
必需的

<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td class="snip">We are looking for physically fit individuals to fill general labour requirements by partnering with a truck driver. Your help is needed to load/unload the truck at the various job sites.
<b>Skills required: </b>
- comfortable with physical exertion and lifting minimum of 50lbs
- works well on a team but trusted to work independently
- reliable, self-motivated and committed to high standards of quality
- able to read and understand work instructions
<b></b>
<i></i></td>
</tr>
</tbody>
</table>

我们正在寻找身体健康的个人,通过与卡车司机合作来满足一般劳动要求。需要您的帮助才能在各个工作现场装卸卡车。
所需技能:
-舒适的体力消耗和最低50磅的举重
-在团队中工作良好,但可以独立工作
-可靠,自我激励,致力于高质量标准
-能够阅读和理解工作说明

我使用了类似于“你好”的东西。子字符串(0,8)

您可以使用
cheerio
库来:

const cheerio=require('cheerio');
常量输入=`
我们正在寻找身体健康的个人,通过与卡车司机合作来满足一般劳动要求。需要您的帮助才能在各个工作现场装卸卡车。
所需技能:
-舒适的体力消耗和最低50磅的举重
-在团队中工作良好,但可以独立工作
-可靠,自我激励,致力于高质量标准
-能够阅读和理解工作说明
具体要求:
-身体状况良好
-必须有自己的安全鞋
-可靠的交通,确保准时和一致的出勤
如果您符合上述资格,请通过以下链接以MS Word格式提交您的简历。
以前受雇于员工关系?请联系我们的办公室,确认您是否能继续胜任这些即将到来的职位。
`;
const result=cheerio.load(input.substring(0200),{xmlMode:true});
log(result.html());

示例:

您想要的是完全没有标记的文本吗?或者您希望保留HTML,但将其限制为文本的前100个字符?您的代码运行在什么环境中?(浏览器?节点?)@rayhatfield我想保留HTML,我使用NodeHello!如果只显示100个字母,您希望实现什么?当post answer=)我更改node.js的解决方案和新条件时,我没有看到此注释。