javascript - TypeError:无法在“节点”上执行“removeChild”:参数 1 不是“节点”类型
问题描述
此错误的可能来源是什么?我要实现的目标的简要背景。我找到了一个 epub 刮板,它可以下载网页并将网页的内容刮到 epub 中。我试图编辑js,但遇到了这个错误。以前,我成功下载了 1 个 epub,但现在卡在第 9 章。
堆栈跟踪错误:
TypeError:无法在“节点”上执行“removeChild”:参数 1 不是“节点”类型。 在 Object.convert (C:\Users\T\AppData\Roaming\npm\node_modules\worm-scraper\node_modules\jsdom\lib\jsdom\living\generated\Node.js:749:11) 在 HTMLDivElement.removeChild (C:\Users\T\AppData\Roaming\npm\node_modules\worm-scraper\node_modules\jsdom\lib\jsdom\living\generated\Node.js:323:29) 在 getBodyXML (C:\Users\T\AppData\Roaming\npm\node_modules\worm-scraper\lib\convert.js:60:15) 在 getChapterString (C:\Users\T\AppData\Roaming\npm\node_modules\worm-scraper\lib\convert.js:40:16) 在 convertChapter (C:\Users\T\AppData\Roaming\npm\node_modules\worm-scraper\lib\convert.js:27:18) 在 <匿名>
我认为导致问题的代码是:
function getBodyXML(chapter, contentEl) {
// Remove initial Next Chapter and Previous Chapter <p>
//contentEl.removeChild(contentEl.firstElementChild);
// Remove everything after the last <p> (e.g. analytics <div>s)
const lastP = contentEl.querySelector("p:last-of-type");
while (contentEl.lastElementChild !== lastP) {
contentEl.removeChild(contentEl.lastElementChild);
}
// Remove empty <p>s or Last Chapter/Next Chapter <p>s
while (isEmptyOrGarbage(contentEl.lastElementChild)) {
contentEl.removeChild(contentEl.lastElementChild);
}
// Remove redundant attributes and style
Array.prototype.forEach.call(contentEl.children, child => {
if (child.getAttribute("dir") === "ltr") {
child.removeAttribute("dir");
}
// Only ever appears with align="LEFT" (useless) or align="CENTER" overridden by style="text-align: left;" (also
// useless)
child.removeAttribute("align");
if (child.getAttribute("style") === "text-align:left;") {
child.removeAttribute("style");
}
if (child.getAttribute("style") === "text-align:left;padding-left:30px;") {
child.setAttribute("style", "padding-left:30px;");
}
});
如果有帮助,将调用原始刮板并在此处worm-scraper
上传编辑后的版本
解决方案
推荐阅读
- python - 时间数据 '03/16/2021 5:06 PM' 与格式 '%d/%m/%Y %I:%M %p' 不匹配
- node.js - 当我尝试在 MongoDB 数据库中上传图像时,出现 multer 错误
- php - magento 2.4.1 的单个产品详细信息页面上未显示带有简单消息的自定义构建模块?
- spring - SFTP 出站网关错误 - 文件列表命令
- python - Python Caplog 不捕获自定义记录器但捕获默认记录器
- terminal - PyCharm 不支持“ALT”的解决方法。到现在
- r - 绘制具有相邻两个向量的直方图
- apache-kafka - Apache Beam、KafkaIO 至少一次语义
- python - 如何使用 django 添加登录用户的用户名
- python - 如何在 discord.py 聊天中共享 mp3 文件