-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_seo_data.gs
80 lines (65 loc) · 3.03 KB
/
check_seo_data.gs
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
function countOutlinks() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var outlinksSheet = spreadsheet.getSheetByName("Outlinks");
var uniqueOutlinksSheet = spreadsheet.getSheetByName("Unique Outlinks");
if (!outlinksSheet) {
outlinksSheet = spreadsheet.insertSheet("Outlinks");
}
if (!uniqueOutlinksSheet) {
uniqueOutlinksSheet = spreadsheet.insertSheet("Unique Outlinks");
}
var currentDate = new Date().toLocaleDateString("de-DE");
var lastOutlinkColumn = outlinksSheet.getLastColumn() + 1;
var lastUniqueOutlinkColumn = uniqueOutlinksSheet.getLastColumn() + 1;
var urls = outlinksSheet.getRange(2, 1, outlinksSheet.getLastRow() - 1, 1).getValues();
urls.forEach(function(url, index) {
url = url[0];
if (url) {
try {
var html = UrlFetchApp.fetch(url).getContentText();
var outlinks = html.match(/<a [^>]*href="(\/[^\/"][^"]*|https:\/\/www\.aponeo\.de[^"]*)"/g);
if (outlinks) {
var uniqueOutlinks = [...new Set(outlinks)];
outlinksSheet.getRange(1, lastOutlinkColumn).setValue(currentDate);
outlinksSheet.getRange(index + 2, lastOutlinkColumn).setValue(outlinks.length);
uniqueOutlinksSheet.getRange(1, lastUniqueOutlinkColumn).setValue(currentDate);
uniqueOutlinksSheet.getRange(index + 2, lastUniqueOutlinkColumn).setValue(uniqueOutlinks.length);
}
} catch (error) {
console.error("Fehler beim Abrufen der URL " + url + ": " + error.message);
outlinksSheet.getRange(index + 2, lastOutlinkColumn).setValue("Fehler");
uniqueOutlinksSheet.getRange(index + 2, lastUniqueOutlinkColumn).setValue("Fehler");
}
}
// Pausieren für 143 Millisekunden (1 Sekunde / 7 Anfragen = ~143 Millisekunden)
Utilities.sleep(143);
});
}
function checkResponseTimes() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var responseTimesSheet = spreadsheet.getSheetByName("Response Times");
if (!responseTimesSheet) {
responseTimesSheet = spreadsheet.insertSheet("Response Times");
}
var currentDate = new Date().toLocaleDateString("de-DE");
var lastResponseTimeColumn = responseTimesSheet.getLastColumn() + 1;
var urls = responseTimesSheet.getRange(2, 1, responseTimesSheet.getLastRow() - 1, 1).getValues();
urls.forEach(function(url, index) {
url = url[0];
if (url) {
try {
var startTime = new Date().getTime();
var response = UrlFetchApp.fetch(url);
var endTime = new Date().getTime();
var responseTime = endTime - startTime;
responseTimesSheet.getRange(1, lastResponseTimeColumn).setValue(currentDate);
responseTimesSheet.getRange(index + 2, lastResponseTimeColumn).setValue(responseTime);
} catch (error) {
console.error("Fehler beim Abrufen der URL " + url + ": " + error.message);
responseTimesSheet.getRange(index + 2, lastResponseTimeColumn).setValue("Fehler");
}
}
// Pausieren für 143 Millisekunden (1 Sekunde / 7 Anfragen = ~143 Millisekunden)
Utilities.sleep(143);
});
}