I am trying to trigger a JavaScript file from an HTML component by clicking on a button, but nothing happens when I click the button:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<p id="counter">Loading button click data.</p>
<button id="buttonForScraping">begin to scrape!</button>
<script>
function startScrape(){
jQuery.ajax({
type:'get',
url:'../../../scraping.js',
data:[],
dataType:'json',
success: function(rs)
{},
failure : function(rs)
{}
});
}
</script>
</body>
</html>
The above code contains the HTML and the following is the JavaScript code:
const {exec} = require('child_process');
const button = window.document.getElementById('buttonForScraping');
button.addEventListener('click', function(e) {
exec('scrapy crawl address', (err, stdout, stderr) => {
console.log(`stdout: ${stdout}`);
console.log(`stderr: ${stderr}`);
});});
Since the scrapy command is a Python command, I believe an ajax call needs to be made in order to run it on the server.