0

I tried to scrape amazon product details using scraping api but it shows me following error:

"message": "Error: getaddrinfo ENOTFOUND api.scrapapi.com",
"cause": {
"errno": -3008,
"code": "ENOTFOUND",
"syscall": "getaddrinfo",
"hostname": "api.scrapapi.com"
 },

My whole code snippet is given below. Please help me to fix this problem

const { response } = require('express');
const express = require('express');
const { reset } = require('nodemon');
const request = require('request-promise');

const app = express();
const PORT = process.env.PORT || 5500;

const apiKey = "api_key";
const apiUrl = `http://api.scrapapi.com?api_key=${apiKey}&autoparse=true`;

app.use(express.json());

app.get('/',(req,res) =>{
res.send('Daraz api scraper');
});

//get product id
app.get('/products/:productId',async(req,res)=>{
const {productId} = req.params;
try {
    const response = await 
    request(`${apiUrl}&url=https://www.amazon.com/dp/${productId}`);
    res.json(JSON.parse(response));
} catch (error) {
    res.json(error);
}

});

1 Answers1

0

I have already sorted it out. My code was right but all was the silly mistake that i did in my code that i wrote the wrong scrapeerapi thats why unknown hostname responded with error.