Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.get("/api/fetch", (req, res) => {
- return axios.get("http://www.nationalreview.com/").then(response => {
- const $ = cheerio.load(response.data);
- let articles = [];
- $(".homepage_meta").each(function(i, element) {
- let result = {};
- result.title = $(this)
- .children(".homepage_item_title")
- .text();
- result.summary = $(this)
- .children(".homepage_item_body")
- .text();
- result.url = `www.nationalreview.com/${element.parent.attribs.href}`;
- result.saved = false;
- articles.push(result);
- });
- db.Article.create(articles).catch(err => console.log("err: ", err));
- res.send({
- message: "Scrape Complete"
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement