Javascript access another webpage

╄→гoц情女王★ 提交于 2019-11-28 23:46:59
Daniel Vassallo

There is the XMLHttpRequest, but that would be limited to the same domain of your web site, because of the Same Origin Policy.

However, you may be interested in checking out the following Stack Overflow post for a few solutions around the Same Origin Policy:


UPDATE:

Here's a very basic (non cross-browser) example:

var xhr = new XMLHttpRequest();
xhr.open('GET', '/questions/3315235', true);
xhr.onreadystatechange = function() {
  if (xhr.readyState === 4)  { 
    console.log(xhr.responseText);
  }
};
xhr.send(null);

If you run the above in Firebug, with Stack Overflow open, you'd get the HTML of this question printed in your JavaScript console:

JavaScript access another webpage http://img217.imageshack.us/img217/5545/fbugxml.png

You could issue an AJAX request and process it.

Write your own server, which runs the script to load the data from websites. Then from your web page, ask your server to fetch the data from websites and send them back to you.

see http://www.storminthecastle.com/2013/08/25/use-node-js-to-extract-data-from-the-web-for-fun-and-profit/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!