可以jquery读取外部页面的dom元素吗? [英] can jquery read the dom elements of external pages?

查看:132
本文介绍了可以jquery读取外部页面的dom元素吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以阅读和解析cnn.com(例如)等第三方网站的dom元素,以便我可以获取div,a,p标签并阅读位置和大小信息?

Is it possible to read and parse the dom elements of third party websites like cnn.com (for e.g) so that I can get the div, a, p tags and read the position and size information?

jquery可以解析并显示您的JavaScript代码正在运行的网页的信息,但如果我们提供外部网页到.load命令,我们可以解析第三方网站页面并阅读DOM树?

jquery can parse and show information of the web page where your javascript code is running but if we provide an external web page to the .load command, can we parse the third party website page and read the DOM tree?

谢谢

推荐答案

不,你会被同源政策阻止,限制一个网站访问另一个网站上的其他网站。您可以使用您首选的语言来设置服务器端脚本,这将代表您的JavaScript代码获取网站,但这比使用AJAX请求页面更复杂。

No, you will be blocked by the Same Origin Policy, which restricts one site from accessing another on a different domain. You could set up a server-side script, in your preferred language, which would fetch the website on behalf of your JavaScript code, but this is more complex than just using AJAX to request the page.

这篇关于可以jquery读取外部页面的dom元素吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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