basic frontend demo with react and redux
This commit is contained in:
39
backend/index.js
Normal file
39
backend/index.js
Normal file
@@ -0,0 +1,39 @@
|
||||
let fetch = require("node-fetch");
|
||||
let cheerio = require("cheerio");
|
||||
let express = require("express");
|
||||
const path = require("path");
|
||||
const bodyParser = require("body-parser");
|
||||
let fs = require("fs");
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 5000;
|
||||
|
||||
app.get("/api/:url", async (req, res) => {
|
||||
let url = "https://www.olx.ba/pretraga?" + req.params.url;
|
||||
let appts = [];
|
||||
response = await fetch(url);
|
||||
const body = await response.text();
|
||||
|
||||
const $ = cheerio.load(body);
|
||||
|
||||
$("#rezultatipretrage")
|
||||
.find(".listitem")
|
||||
.each(async (i, elem) => {
|
||||
const id = $(elem)
|
||||
.find("a")
|
||||
.first()
|
||||
.attr("href");
|
||||
const cijena = $(elem)
|
||||
.find(".cijena > .datum > span")
|
||||
.first()
|
||||
.text();
|
||||
const image = $(elem)
|
||||
.find("a > .slika > img")
|
||||
.first()
|
||||
.attr("src");
|
||||
appts.push({ url: id, price: cijena, image });
|
||||
});
|
||||
res.json(appts);
|
||||
});
|
||||
|
||||
app.listen(port, () => console.log(`Example app listening on port ${port}!`));
|
||||
Reference in New Issue
Block a user