Download von HTML-Content in lokaler Datenbank via JS, Node und MySQL (MariaDB)

jemand anders

Erfahrenes Mitglied
Hallo,

wie schon im Titel gesagt möchte ich von Webseiten meiner Wahl durch Klick auf ein Scriptlet Content herunterladen und in einer lokalen Datenbank speichern.

Das Scriptlet ruft dazu auf dem Localhost den File s1.js und der soll wiederum s2.js aufrufen. Das wird aber nicht gemacht. Fehlermeldung:

Loading failed for the <script> with source “http://localhost/TestP1/s1.js”. Access-Control-Allow-Origin:1:1
Content Security Policy: Die Einstellungen der Seite haben das Laden einer Ressource auf http://localhost/TestP1/s1.js blockiert ("script-src"). s1.js";})();:1:26

Weiß jemand, ob das ein generelles Problem ist oder nur ein Fehler in meinem Code? Wie bekomme ich sie ggf. weg bzw. was sollte ich generell ändern?

Grüße

Files:


Javascript:
// File: http://localhost/TestP1/s1.js

// Aufruf: javascript:(function(){document.body.appendChild(document.createElement('script')).src="http://localhost/TestP1/s1.js";})();

console.clear()

var title = document.title

console.log("Title = " + title)

var request = new Request("http://localhost/TestP1/s2.js", {
    method: "POST",
    body: {
        title: "Title4711"
    },
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json'
    }
})

fetch(request).then(function() {
    for (r in request) {
        console.log(r + " -> " + request.r)
    }
    console.log('response' + request)
})



Javascript:
 // // File: http://localhost/TestP1/s2.js
/*

Funktionierender Aufruf via Konsole:

    $ node s2.js {"arg1":"Argument 1"}

+----------------------+
[ '{arg1:Argument 1}' ]
titles id => 29
+----------------------+
*/

let mysql = require("mysql");
let config = require("./config.js");
let connection = mysql.createConnection(config);

let stmt = `insert into titles (bez) values (?)`;

let value = ["title", false];


var args = process.argv.slice(2);
console.log(args);

connection.query(stmt, value, (err, results, fields) => {
    if (err) {
        return console.error(err.message);
    }
    console.log("titles id => " + results.insertId);
});

connection.end();

/*

$ desc titles;
+-------+--------------+------+-----+---------+----------------+
| Field | Type         | Null | Key | Default | Extra          |
+-------+--------------+------+-----+---------+----------------+
| id    | int(5)       | NO   | PRI | NULL    | auto_increment |
| bez   | varchar(200) | YES  |     | NULL    |                |
+-------+--------------+------+-----+---------+----------------+

*/



Javascript:
// config.js

let config = {
    host: "localhost",
    user: "gast",
    password: "gast",
    database: "test",
};

module.exports = config;


Code:
create table if not exists titles (
    id  int(5) not null auto_increment unique primary key,
    bez varchar(200)
) engine=InnoDB default charset=utf8;

GRANT ALL PRIVILEGES ON test.* TO 'gast';
 
Zuletzt bearbeitet:

Neue Beiträge

Zurück