forked from borjiso/node-red-contrib-scrape-it
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscrape-it.html
116 lines (108 loc) · 3.89 KB
/
scrape-it.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<script type="text/javascript">
RED.nodes.registerType('scrape',{
category: 'parser',
color: '#a6bbcf',
defaults: {
name: {value:""},
mapping: {value:""},
sourceProperty: {value:"payload", required:false},
targetProperty: {value:"payload", required:true}
},
inputs:1,
outputs:1,
icon: "font-awesome/fa-code",
label: function() {
return this.name||"scrape";
},
oneditprepare: function(){
$("#node-input-sourceProperty").typedInput({
type:"msg",
types:["msg"],
typeField: "#node-input-sourcePropertyType"
});
$("#node-input-targetProperty").typedInput({
type:"msg",
types:["msg"],
typeField: "#node-input-targetPropertyType"
});
this.editor = RED.editor.createEditor({
id: 'node-input-mapping-editor',
mode: 'ace/mode/json',
value: $("#node-input-mapping").val()
});
this.editor.focus();
},
oneditsave: function(){
console.log('oneditsave');
$("#node-input-mapping").val(this.editor.getValue());
console.log(`node-input-mapping: ${$('#node-input-mapping').val()}`);
this.editor.destroy();
delete this.editor;
},
oneditcancel: function(){
console.log('oneditcancel');
this.editor.destroy();
delete this.editor;
},
oneditresize: function(size){
console.log('oneditresize');
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0; i<rows.size(); i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
this.editor.resize();
}
});
</script>
<script type="text/html" data-template-name="scrape">
<div class="form-row">
<label for="node-input-name"><i class="fa fa-tag"></i> Name</label>
<input type="text" id="node-input-name" placeholder="Name">
</div>
<div class="form-row">
<label for="node-input-sourceProperty"><i class="fa fa-ellipsis-h"></i> Property</label>
<input type="text" id="node-input-sourceProperty" placeholder="">
</div>
<div class="form-row">
<label for="node-input-targetProperty"><i class="fa fa-random"></i> Output</label>
<input type="text" id="node-input-targetProperty" placeholder="">
</div>
<div class="form-row" style="margin-bottom: 0px;">
<label for="node-input-mapping" style="width:fit-content"><i class="fa fa-file-code-o"></i> Scrape-It Query</label>
<input type="hidden" id="node-input-mapping" autofocus="autofocus">
</div>
<div class="form-row node-text-editor-row">
<div style="height: 250px; min-height:150px;"
class="node-text-editor"
id="node-input-mapping-editor" ></div>
</div>
</script>
<script type="text/html" data-help-name="scrape">
<p>Scrape html request</p>
<h3>Inputs</h3>
<dl class="message-properties">
<dt>payload
<span class="property-type">string</span>
</dt>
<dd> the html to be parsed. </dd>
</dl>
<h3>Outputs</h3>
<ol class="node-ports">
<li>html parsed to JSON
<dl class="message-properties">
<dt>payload <span class="property-type">JSON</span></dt>
<dd>html parsed as defined in mapping property</dd>
</dl>
</li>
</ol>
<h3>Details</h3>
<p>Mapping property define how to transform html to JSON.</p>
<h3>References</h3>
<ul>
<li><a href="https://github.com/cheeriojs/cheerio#-selector-context-root">Selectors section of the Cheerio library</a></li>
</ul>
</script>