如何从一个网页(不同的域名)获取html代码? [英] How to get the html code from a web page (different domain)?

查看:771
本文介绍了如何从一个网页(不同的域名)获取html代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何创建一个javascript脚本,使我可以从另一个域获取不同页面的html代码,并允许我编辑和显示代码?感谢您的提前。

解决方案

这在天真的意义上是不可能的,因为您将被javascript的相同域策略杀死。

现在,如果您有权访问自己的Web服务器,则可以设置一个服务来侦听您的请求,其中包含要提取的第三方网址。您的服务将为第三方域拉取源代码并将其作为对您的请求的响应返回。然后,您将该响应添加到可编辑字段中。

编辑:这个答案与YQL(雅虎查询语言)的答案似乎是一样的原则,也发布了。

How can I create a javascript script that allows me to get the html code of a different page from a different domain and allows me to edit and display the code?? Thanks in advance.

解决方案

This isn't possible in the naive sense because you will get killed by javascript's same domain policy.

Now if you have access to your own web server, you could set up a service that listens for your request which would include a 3rd party URL to fetch. Your service would pull the source for the 3rd party domain and return it as the response to your request. Then you take that response and append it into your editable field.

EDIT: This answer seems to be the same principle as the YQL (Yahoo Query Language) answer that was posted as well.

这篇关于如何从一个网页(不同的域名)获取html代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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