简体   繁体   English

如何使用 axios 加载 JavaScript 启用的响应或在 Z686155AF75A160A0F6EZE9D8 中获取 API?

[英]How to load JavaScript enabled response using axios or fetch API in JavaScript?

I am working on a personal project in which I want to read the whole HTML of a JavaScript dependent webpage.我正在做一个个人项目,我想在其中阅读 JavaScript 相关网页的整个 HTML。 For Example if I to load this URL in a JavaScript Enabled web browser, this is what I get:例如,如果我在 JavaScript 启用 web 浏览器中加载此 URL ,这就是我得到的:

Instagram 上的图片帖子

However, if I disable JavaScript in the browser, and load the same URL now, I get this:但是,如果我在浏览器中禁用 JavaScript,并现在加载相同的 URL ,我会得到:

只有 Instagram LOGO

This is pretty normal I know.我知道这很正常。


Now I am trying to load the HTML of the same link in JavaScript code using axios HTTP client, and obviously I am getting the HTML of JavaScript disabled webpage as the HTTP response. Now I am trying to load the HTML of the same link in JavaScript code using axios HTTP client, and obviously I am getting the HTML of JavaScript disabled webpage as the HTTP response.

I want to get the HTML(+JS) source as the response of the same link (in which JavaScript is enabled).我想获取 HTML(+JS) 源作为同一链接的响应(其中启用了 JavaScript)。 I don't know how to mimic a JavaScript enabled Web Browser when working with HTTP clients like axios or fetch API. I don't know how to mimic a JavaScript enabled Web Browser when working with HTTP clients like axios or fetch API.

If you're trying to do this in the browser, you basically can't unless the site you're loading lets you do so (via CORS or similar).如果您尝试在浏览器中执行此操作,除非您正在加载的站点允许您这样做(通过CORS或类似网站),否则您基本上不能这样做。 You'd have to load it into a window or iframe , wait for its JavaScript to run, and then access the resulting DOM.您必须将其加载到 window 或iframe中,等待其 JavaScript 运行,然后访问生成的 DOM。 But accessing the DOM of a cross-origin page is disabled by default.但是默认情况下禁用访问跨域页面的 DOM。

The only browser-based way I can think of is to write and install a browser extension , since when a user installs an extension, they can grant greater power to the extension than a web page normally has.我能想到的唯一基于浏览器的方法是编写和安装浏览器扩展,因为当用户安装扩展时,他们可以为扩展授予比 web 页面通常具有的更大的权力。

If you're trying to do this in a non-browser environment, you can use a headless browser like headless Chromium or similar.如果您尝试在非浏览器环境中执行此操作,则可以使用无头浏览器,如无头 Chromium 或类似浏览器。 The browser-based restrictions don't apply.基于浏览器的限制不适用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 axios 获取和映射 api 响应数据 - How to fetch and map api response data using axios 如何知道获取 Api javascript 的响应的 state? - how to know the state of a response with fetch Api javascript? Javascript - 如何知道 Fetch API 中响应的类型? - Javascript - How to know the type of the response in Fetch API? 在获取api中的javascript中重新响应 - response rearraging in javascript in fetch api 如何使用javascript / axios从服务器访问错误响应 - How to access error response from server using javascript / axios Javascript-Axios在for循环中。 在下一次获取数据的迭代中使用当前获取的响应 - Javascript - Axios in for loop. Using the response of current fetch for the next iteration of fetching data 尝试使用 Fetch 在 JavaScript 中记录来自 REST API 的 JSON 响应 - Attempting to log JSON response from REST API in JavaScript using Fetch 使用axios捕获来自404响应的错误消息或在javascript中获取 - catch error message from 404 response with axios or fetch in javascript 如何使用 Rails API 在 Javascript 中获取删除 - How to fetch delete in Javascript using Rails API 使用纯 javascript 和引导程序:如何显示模式对话框确认来自 JSON API 的提取操作的响应 - Using pure javascript and Bootstrap : How to display a modal dialog confirm response from fetch operation from JSON API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM