如何从我的JS文件中动态访问另一个DOM(Yahoo Finance)[重复]

时间:2022-03-09 16:02:38

This question already has an answer here:

这个问题在这里已有答案:

I'd like to get some data regarding stocks from :http://finance.yahoo.com/q?s=AAPL and i'm wondering if there is any way to accees the DOM of this page from my application. Let's say i have the this query: http://finance.yahoo.com/q?s=AAPL, i tried to access the DOM from the Chrome console : console.log (document.head.innerText), but o couldn't find a way to access it using my local script file.

我想从以下网站获取一些关于股票的数据:http://finance.yahoo.com/q?s = AAPL,我想知道是否有任何方法可以从我的应用程序中加入此页面的DOM。假设我有这个查询:http://finance.yahoo.com/q?s = AAPL,我试图从Chrome控制台访问DOM:console.log(document.head.innerText),但是o couldn'找到一种使用我的本地脚本文件访问它的方法。

2 个解决方案

#1


1  

You won't be able to access directly the content of that page from another page in Javascript, because of same-origin policy (given that your app is a website on another domain). The best way would be to write a backend working as a proxy and API for your app. Or maybe Yahoo finances already has a public API ;)

您将无法直接从Javascript中的其他页面访问该页面的内容,因为同源策略(假设您的应用是另一个域中的网站)。最好的方法是编写后端作为应用程序的代理和API。或者雅虎的财务状况已经有了公共API;)

#2


-1  

You can't access the DOM with cross domain. In other hand you can make a GET request with jQuery before exploit the DOM.

您无法使用跨域访问DOM。另一方面,您可以在利用DOM之前使用jQuery发出GET请求。

#1


1  

You won't be able to access directly the content of that page from another page in Javascript, because of same-origin policy (given that your app is a website on another domain). The best way would be to write a backend working as a proxy and API for your app. Or maybe Yahoo finances already has a public API ;)

您将无法直接从Javascript中的其他页面访问该页面的内容,因为同源策略(假设您的应用是另一个域中的网站)。最好的方法是编写后端作为应用程序的代理和API。或者雅虎的财务状况已经有了公共API;)

#2


-1  

You can't access the DOM with cross domain. In other hand you can make a GET request with jQuery before exploit the DOM.

您无法使用跨域访问DOM。另一方面,您可以在利用DOM之前使用jQuery发出GET请求。