V
V
Vladimir2019-06-26 22:58:30
JavaScript
Vladimir, 2019-06-26 22:58:30

Load markup from another site via cors ajax?

How to download markup from another site through a browser script? For example, I need to get certain meta tags from yandex.ru.

The article https://developer.mozilla.org/ru/docs/Web/HTTP/CORS says that there are "simple" requests, if I use GET and do not use non-standard headers, then everything should work.
Here is the code:

fetch('https://bootstrap-vue.js.org')
    .then(res => res.text())
    .then(res => {
        console.log(res)
    })
    .catch(err => console.log(err))


It works, but not on all sites, for example, on https://bootstrap-vue.js.org it works, but if I turn to Yandex, then the error
5d13cda6e1674914664503.png
I tried to add different headers, I tried to use different modes for fetch, but it didn’t work out.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stalker_RED, 2019-06-26
@drop9dead

fetch is also ajax, not a simple GET.
Or set up that other server, or use your own proxy (you can even cache ☝), or refuse ajax.

G
grinat, 2019-06-26
@grinat

For simple ones to work, there must be alow origin from the origin from which you make the request or from *.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question