J
J
jekanok2021-02-25 17:17:09
RSS
jekanok, 2021-02-25 17:17:09

How to parse rss yahoo in vue.js?

Hello, there is a problem with the fact that there is a link to the rss feed, when we open it in the browser it works fine, but when you feed it, get it through js

mounted() {
    fetch("https://www.yahoo.com/news/rss")
      .then((response) => response.text())
      .then((data) => {
        const parser = new DOMParser();
        const xml = parser.parseFromString(data, "application/xml");
        console.log(xml);
      })
      .catch(console.error);
}
,
gives an error:
Access to fetch at ' https://www.yahoo.com/news/rss ' from origin ' localhost:8080 ' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
6037b0f61325c204818531.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly Kulikov, 2021-02-25
@jekanok

The simplest solution would be to write a simple backend, which will return this data to you in the application.
Minimum: php/nodejs, which simply takes an address as input and returns the rss it receives (it can be quite successfully converted to json).
Ideal: a microservice that periodically requests data from addresses and saves it to the database (or at least just as a file), and returns it when requested from your vue application.

A
Anton Anton, 2021-02-25
@Fragster

fetch("https://www.yahoo.com/news/rss", {
    mode: 'no-cors', // no-cors, *cors, same-origin
})

more details here https://developer.mozilla.org/ru/docs/Web/API/Fetc...
and here https://developer.mozilla.org/ru/docs/Web/HTTP/CORS

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question