我遇到了 BSL 问题。我想将我的代码分成单独的辅助文件并使用
\n\n(require "auxiliary-function.rkt") \nRun Code Online (Sandbox Code Playgroud)\n\n首先将分离的代码导入到定义区域。然而它并没有像想象的那样工作。虽然没有给出明确的错误,但似乎 DrRacket 根本看不到单独文件中的代码,而我看到的只是错误
\n\n<auxiliary-function-name>: this function is not defined \nRun Code Online (Sandbox Code Playgroud)\n\n显然,
\n\n(provide x)\nRun Code Online (Sandbox Code Playgroud)\n\n不包含在 BSL 中。我已经阅读了手册和这个答案,但 xe2x80x99s 仍然不清楚如何进行这项工作。这在 BSL 中可能吗?
\n\n谢谢!
\n我想使用 Node.js 的htmlparser2模块解析一些 html。我的任务是通过 ID 找到精确的元素并提取其文本内容。
我已阅读文档(相当有限),并且知道如何使用该onopentag函数设置解析器,但它只允许访问标签名称及其属性(我看不到文本)。该ontext函数从给定的 html 字符串中提取所有文本节点,但忽略所有标记。
这是我的代码。
const htmlparser = require("htmlparser2");
const file = '<h1 id="heading1">Some heading</h1><p>Foobar</p>';
const parser = new htmlparser.Parser({
onopentag: function(name, attribs){
if (attribs.id === "heading1"){
console.log(/*how to extract text so I can get "Some heading" here*/);
}
},
ontext: function(text){
console.log(text); // Some heading \n Foobar
}
});
parser.parseComplete(file);
Run Code Online (Sandbox Code Playgroud)
我期望函数调用的输出为'Some heading'. 我相信有一些明显的解决方案,但不知何故它忽略了我的想法。
谢谢。