如何在 cheerios 中获取 line no?它是特定于版本的吗
How to get line no in cheerios ? is it version specific
我想获取 html 标签的行号。使用 cheerios 解析 html 时
我发现如果我使用这个 {withStartIndices : true} 然后得到行号但我使用的是版本 "@types/cheerio": "^0.22.17", "cheerio": "^1.0.0- rc.3
这是我的代码::
// const $ = load(htmlPage, { xmlMode: true, withStartIndices : true }); getting error withStartIndices that not a property
const $ = load(htmlPage, { xmlMode: true });
$('b').each((index, el) => {
const text: string = $(el).contents().first().text();
if (text.toLowerCase().includes('data:')) {
bottomInfo.isExist = true;
bottomInfo.lineNo = $(el).get(0);
/* already tried
bottomInfo.lineNo = $(el).get(0).startIndex;
bottomInfo.lineNo = $(el).startIndex;
*/
}
});
我怎样才能得到行号
几个小时后,我检查 withStartIndices : true 不适用于打字稿 "@types/cheerio": "^0.22.17" 我直接使用 "cheerio": "^1.0.0- rc.3",它对我很好
我想获取 html 标签的行号。使用 cheerios 解析 html 时 我发现如果我使用这个 {withStartIndices : true} 然后得到行号但我使用的是版本 "@types/cheerio": "^0.22.17", "cheerio": "^1.0.0- rc.3
这是我的代码::
// const $ = load(htmlPage, { xmlMode: true, withStartIndices : true }); getting error withStartIndices that not a property
const $ = load(htmlPage, { xmlMode: true });
$('b').each((index, el) => {
const text: string = $(el).contents().first().text();
if (text.toLowerCase().includes('data:')) {
bottomInfo.isExist = true;
bottomInfo.lineNo = $(el).get(0);
/* already tried
bottomInfo.lineNo = $(el).get(0).startIndex;
bottomInfo.lineNo = $(el).startIndex;
*/
}
});
我怎样才能得到行号
几个小时后,我检查 withStartIndices : true 不适用于打字稿 "@types/cheerio": "^0.22.17" 我直接使用 "cheerio": "^1.0.0- rc.3",它对我很好