本文整理汇总了TypeScript中cheerio类的典型用法代码示例。如果您正苦于以下问题:TypeScript cheerio类的具体用法?TypeScript cheerio怎么用?TypeScript cheerio使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了cheerio类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: cheerio
/*
* LOADING
*/
let html =
`<ul id="fruits">
<li class="orange">Apple</li>
<li class="class">Orange</li>
<li class="pear">Pear</li>
<input type="text" />
</ul>`;
// Preferred Method
var $ = cheerio.load(html);
// Directly load element
cheerio(html);
cheerio('ul', html);
cheerio('li', 'ul', html);
const $fromElement = cheerio.load($("ul").get(0));
if ($fromElement("ul > li").length !== 3) {
throw new Error("Expecting 3 elements when passing `CheerioElement` to `load()`");
}
$ = cheerio.load(html, {
normalizeWhitespace: true,
xmlMode: true
});
$ = cheerio.load(html, {
开发者ID:CNManning,项目名称:DefinitelyTyped,代码行数:30,代码来源:cheerio-tests.ts
示例2: _parseTemplate
protected _parseTemplate (template: string): Translations {
let collection: Translations = new Translations();
template = this._normalizeTemplateAttributes(template);
const selector = '[translate], [ng2-translate]';
$(template)
.find(selector)
.addBack(selector)
.each((i: number, element: CheerioElement) => {
const $element = $(element);
const attr = $element.attr('translate') || $element.attr('ng2-translate');
// The key is never the attribute value
// if (attr) {
// collection = collection.add(attr);
// } else {
$element
.contents()
.toArray()
.filter(node => node.type === 'text')
.map(node => node.nodeValue.trim())
.filter(text => text.length > 0)
.forEach(text => collection = collection.add(text));
// }
});
return collection;
}
开发者ID:bvkimball,项目名称:linguist,代码行数:29,代码来源:DirectiveParser.ts
示例3: Error
files.forEach((file) => {
// add few helper methods
extend(file);
const $contents = $(file.getContentsAsString());
const isMain = $contents.closest('head,body').length;
const isTemplate = $contents.closest(':not(head,body)').length;
if (file.isNodeModule()) {
// push directly as a template
templateFiles.push(file);
} else {
// cannot be both
if (isMain && isTemplate) {
const fileName = file.getBasename();
const errorMsg = `${fileName} has wrong layout`;
throw Error(errorMsg);
}
if (isMain > 0) {
mainFiles.push(file);
} else {
templateFiles.push(file);
}
}
});
开发者ID:kamilkisiela,项目名称:meteor-static-html-compiler,代码行数:26,代码来源:index.ts
示例4:
$$$.each((index, element) => {
var tag = element.tagName;
last_child.append(element);
if (contTags[tag.toLowerCase()]) {
paragraphs.push(last_child.html());
last_child = $('<div></div>');
}
});
开发者ID:secondwtq,项目名称:expressus,代码行数:8,代码来源:format.ts
示例5: compileOneFile
public compileOneFile(file): CompileResult {
const $contents = $(file.getContentsAsString());
const $head = $contents.closest('head');
const $body = $contents.closest('body');
return {
head: $head.html() || '',
body: $body.html() || '',
};
}
开发者ID:jellyjs,项目名称:meteor-static-html-compiler,代码行数:10,代码来源:main.ts
示例6: compileOneFile
public compileOneFile(file: FileObject): CompileResult {
const $contents = $(file.getContentsAsString());
const $head = $contents.closest('head');
const $body = $contents.closest('body');
return {
head: {
contents: $head.html() || '',
},
body: {
contents: $body.html() || '',
attrs: $body[0] ? $body[0].attribs : undefined,
},
};
}
开发者ID:kamilkisiela,项目名称:meteor-static-html-compiler,代码行数:15,代码来源:main.ts
示例7: splitCallbackWithCheerio
export function splitCallbackWithCheerio(content: Cheerio): SplitResult {
var $$ = $.load('<div id="outermost"></div>');
$$('#outermost').append(content);
var $$$ = $$('#outermost > *');
var last_child = $('<div></div>');
var paragraphs = [ ];
$$$.each((index, element) => {
var tag = element.tagName;
last_child.append(element);
if (contTags[tag.toLowerCase()]) {
paragraphs.push(last_child.html());
last_child = $('<div></div>');
}
});
return paragraphs;
}
开发者ID:secondwtq,项目名称:expressus,代码行数:17,代码来源:format.ts
示例8:
.each((i: number, element: CheerioElement) => {
const $element = $(element);
const attr = $element.attr('translate') || $element.attr('ng2-translate');
// The key is never the attribute value
// if (attr) {
// collection = collection.add(attr);
// } else {
$element
.contents()
.toArray()
.filter(node => node.type === 'text')
.map(node => node.nodeValue.trim())
.filter(text => text.length > 0)
.forEach(text => collection = collection.add(text));
// }
});
开发者ID:bvkimball,项目名称:linguist,代码行数:17,代码来源:DirectiveParser.ts
示例9: splitCallback
export function splitCallback(content: string): SplitResult {
var $$ = $.load(`<div id="outermost">${content}</div>`)
var $$$ = $$('#outermost > *');
var last_child = $('<div></div>');
var paragraphs = [ ];
$$$.each((index, element) => {
var tag = element.tagName;
last_child.append(element);
if (contTags[tag.toLowerCase()]) {
// $.html() would not contain the outer element def.
paragraphs.push(last_child.html());
var new_element = $('<div></div>');
last_child = new_element;
}
});
return paragraphs;
}
开发者ID:secondwtq,项目名称:expressus,代码行数:18,代码来源:format.ts
示例10: Error
files.forEach((file) => {
// skips files from node_modules
if (!!file.getPathInPackage().startsWith('node_modules')) {
return;
}
const $contents = $(file.getContentsAsString());
const isMain = $contents.closest('head,body').length;
const isTemplate = $contents.closest(':not(head,body)').length;
if (isMain && isTemplate) {
const fileName = file.getBasename();
const errorMsg = `${fileName} has wrong layout`;
throw Error(errorMsg);
}
if (isMain > 0) {
mainFiles.push(file);
} else {
templateFiles.push(file);
}
});
开发者ID:jellyjs,项目名称:meteor-static-html-compiler,代码行数:22,代码来源:index.ts
注:本文中的cheerio类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论