简体   繁体   English

代替<head></head>在 html 中

[英]Replace <head></head> in html

How can I replace head tag in html with my own provided code using cheerio?如何使用cheerio用我自己提供的代码替换html中的head标签?

The html structure: html结构:

<!DOCTYPE html>
<html>
<head>
  <title>Example</title>
</head>
<body>

Example html doc......

</body>
</html>

You'd probably want to add something after it, and then remove it:您可能想在它之后添加一些内容,然后将其删除:

$('head').after('<div></div>').remove()

To change the innerHTML use html():要更改 innerHTML 使用 html():

$('head').html('new html')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM