-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZG_Pict_Name.js
152 lines (79 loc) · 3.2 KB
/
ZG_Pict_Name.js
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
function ZG_parser_Pictures_Names() {
// со страницы https://protivogaz.ru/catalog/
// взять ссылки, содержащие https://protivogaz.ru/catalog/
// проходом рекурсивным по этим ссылкам создать массив Названий и ссылок
// если на странице отрабатывают 2 XPath
// массив на лист Картинки
const sURL_start = "https://protivogaz.ru/catalog/";
}
// исследовать
// http://googleappscripting.com/working-with-urls/
// https://web.archive.org/web/20201121023356/http://googleappscripting.com/doget-dopost-tutorial-examples/
// образец для разбора https://www.sites.google.com/site/scriptsexamples/learn-by-example/parsing-html
function doGet01() {
var html = UrlFetchApp.fetch('http://en.wikipedia.org/wiki/Document_Object_Model').getContentText();
var doc = XmlService.parse(html);
var html = doc.getRootElement();
var menu = getElementsByClassName(html, 'vertical-navbox nowraplinks')[0];
var output = XmlService.getRawFormat().format(menu);
return HtmlService.createHtmlOutput(output);
}
// We fetch the HTML through UrlFetch
// We use the XMLService to parse this HTML
// Then we can use a specific function to grab the element we want in the DOM tree (like getElementsByClassName)
// And we convert back this element to HTML
// Or we could get all the links / anchors available in this menu and display them
function doGet() {
var html = UrlFetchApp.fetch('http://en.wikipedia.org/wiki/Document_Object_Model').getContentText();
var doc = XmlService.parse(html);
var html = doc.getRootElement();
var menu = getElementsByClassName(html, 'vertical-navbox nowraplinks')[0];
var output = '';
var linksInMenu = getElementsByTagName(menu, 'a');
for (i in linksInMenu) output += XmlService.getRawFormat().format(linksInMenu[i]) + '<br>';
return HtmlService.createHtmlOutput(output);
}
function getElementById(element, idToFind) {
var descendants = element.getDescendants();
for (i in descendants) {
var elt = descendants[i].asElement();
if (elt != null) {
var id = elt.getAttribute('id');
if (id != null && id.getValue() == idToFind) return elt;
}
}
}
function getElementsByClassName(element, classToFind) {
var data = [];
var descendants = element.getDescendants();
descendants.push(element);
for (i in descendants) {
var elt = descendants[i].asElement();
if (elt != null) {
var classes = elt.getAttribute('class');
if (classes != null) {
classes = classes.getValue();
if (classes == classToFind) data.push(elt);
else {
classes = classes.split(' ');
for (j in classes) {
if (classes[j] == classToFind) {
data.push(elt);
break;
}
}
}
}
}
}
return data;
}
function getElementsByTagName(element, tagName) {
var data = [];
var descendants = element.getDescendants();
for (i in descendants) {
var elt = descendants[i].asElement();
if (elt != null && elt.getName() == tagName) data.push(elt);
}
return data;
}