1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add attribute capability to HTML parser node

This commit is contained in:
Dave Conway-Jones 2015-12-19 12:44:11 +00:00
parent d0f7e5ca4d
commit 08b39f50b3
3 changed files with 8 additions and 7 deletions

View File

@ -531,7 +531,8 @@
},
"output": {
"html": "the html content of the elements",
"text": "only the text content of the elements"
"text": "only the text content of the elements",
"attr": "an object of any attributes of the elements"
},
"format": {
"single": "as a single message containing an array",

View File

@ -23,8 +23,8 @@
<label for="node-input-ret"><i class="fa fa-sign-out"></i> <span data-i18n="html.label.output"></span></label>
<select id="node-input-ret" style="width:76% !important">
<option value="html" data-i18n="html.output.html"></option>
<option value="text"data-i18n="html.output.text"></option>
<!-- <option value="attr">an object of any attributes</option> -->
<option value="text" data-i18n="html.output.text"></option>
<option value="attr" data-i18n="html.output.attr"></option>
<!-- <option value="val">return the value from a form element</option> -->
</select>
</div>

View File

@ -32,9 +32,9 @@ module.exports = function(RED) {
$(node.tag).each(function() {
if (node.as === "multi") {
var pay2 = null;
if (node.ret === "html") { pay2 = $(this).html(); }
if (node.ret === "html") { pay2 = cheerio.load($(this).html().trim()).xml(); }
if (node.ret === "text") { pay2 = $(this).text(); }
//if (node.ret === "attr") { pay2 = $(this)[0]["attribs"]; }
if (node.ret === "attr") { pay2 = this.attribs; }
//if (node.ret === "val") { pay2 = $(this).val(); }
/* istanbul ignore else */
if (pay2) {
@ -43,9 +43,9 @@ module.exports = function(RED) {
}
}
if (node.as === "single") {
if (node.ret === "html") { pay.push( $(this).html() ); }
if (node.ret === "html") { pay.push( cheerio.load($(this).html().trim()).xml() ); }
if (node.ret === "text") { pay.push( $(this).text() ); }
//if (node.ret === "attr") { pay.push( $(this)[0]["attribs"] ); }
if (node.ret === "attr") { pay.push( this.attribs ); }
//if (node.ret === "val") { pay.push( $(this).val() ); }
}
});