Javascript 或 JQuery 从外部站点获取 html 内容 [英] Javascript or JQuery get html content from external site

查看:30
本文介绍了Javascript 或 JQuery 从外部站点获取 html 内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能的重复:
规避同源政策的方法

无论如何要从外部站点获取内容,例如我想从 url http://www.readwriteweb.com/ 在客户端使用 Javascript 或 JQuery

Is there anyway to get content from external site for example i want to get content from url http://www.readwriteweb.com/ in client site by using Javascript or JQuery

推荐答案

这里有两个选项:

  1. 使用 iframe 将外部网站的网页嵌入到您的页面中.您只能嵌入整个页面,包括其所有广告和导航网站,但在某些外部网站上,您可以找到用于移动或打印的页面版本,这些版本在嵌入时可能看起来很合理.
  2. 使用公共 CORS 代理.我发现的唯一一个是 http://www.corsproxy.com/ .我个人对那个网站持怀疑态度,因为没有 TOC、隐私政策,甚至没有任何关于谁运行该网站的迹象.但是,如果您的项目是一些小型项目,您不关心隐私、安全性、可靠性或扩展性,则可以尝试一下.以下是改编自该网站的用法示例:

  1. Use an iframe to embed a web page of the external site in your page. You can only embed an entire page, including all its advertising and navigation sites, but on some external sites you can find versions of the page intended for mobile or for printing that might look reasonable when embedded.
  2. Use a public CORS proxy. The only one I have found is http://www.corsproxy.com/ . Personally I am suspicious of that site as there is no TOC, privacy policy, or even any indication of who runs the site. However if yours is some small project, where you don't care about privacy, security, reliability, or scaling you might try it. Here is an example of usage adapted from the site:

$.get('http://www.corsproxy.com/en.wikipedia.org/wiki/Http',函数(响应){ document.body.innerHTML = 响应;});

$.get( 'http://www.corsproxy.com/en.wikipedia.org/wiki/Http', function(response) { document.body.innerHTML = response; });

这篇关于Javascript 或 JQuery 从外部站点获取 html 内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆