this is my first post here, I was wondering if any web developer can help me out on this one.
So basically, I created a node server using the default options, and linked all my files (index.js, index.html, etc...), I want to scrape a certain site for data and return those data to my index.html or an external file it doesn't really matter.
I just want to be able to click a button on my site that scrapes the other site and returns the data back to my site.
I'm currently using axios and cheerio to do the scraping part, and this is the code:
const axios = require("axios");
const cheerio = require("cheerio");
const fs = require("fs");
function mainSearch() {
axios.get("https://somewebsite.com").then((response) => {
let $ = cheerio.load(response.data);
const titles = [];
$(".title > div > span").each((index, title) => {
titles.push($(title).text());
});
var content = titles.join("\n")
document.write(content)
});
}
function searchFunc() {
mainSearch();
}
then this button calls the "searchFunc" function which runs the main function.
<button onclick="searchFunc()" id="searchbutton">Search</button>
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire