Вам необходимо решить проблемы с CORS с помощью Django бэкэнда, чтобы получить правильный ответ. Я вижу, что ответ имеет следующую структуру:
{
"count": 51,
"next": "http://scrapsh.herokuapp.com/api/post/?page=2",
"previous": null,
"results": [
{
"id": 1,
"title": "asdas",
"rate": 1,
"author": "madhumani",
"content": "asdad",
"review": null,
"url": null
},
{
"id": 2,
"title": "okau",
"rate": 1,
"author": "madhumani",
"content": "asdasd",
"review": null,
"url": null
},
{
"id": 3,
"title": "DASS",
"rate": 1,
"author": "madhumani",
"content": "sdfsdfs",
"review": null,
"url": null
},
...
]
}
Чтобы получить URL, вы можете просто использовать .map
в массиве results
:
let response = {
"count": 51,
"next": "http://scrapsh.herokuapp.com/api/post/?page=2",
"previous": null,
"results": [{
"id": 1,
"title": "asdas",
"rate": 1,
"author": "madhumani",
"content": "asdad",
"review": null,
"url": "www.a.com"
},
{
"id": 2,
"title": "okau",
"rate": 1,
"author": "madhumani",
"content": "asdasd",
"review": null,
"url": "www.b.com"
},
{
"id": 3,
"title": "DASS",
"rate": 1,
"author": "madhumani",
"content": "sdfsdfs",
"review": null,
"url": "www.c.com"
}
]
}
console.log(response.results.map(item => {
return {
"url": item.url
}
}))