如何加载网站HTML使用jquery [英] How to load website HTML using jquery

查看:124
本文介绍了如何加载网站HTML使用jquery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在我的java脚本中加载一些网站,以便我可以解析它?
我想获得Html的www.google.com,我想使用jquery选择其中的所有标签。

How can I load some website in my java-script so that I can parse it? I want to get Html of e.g. www.google.com and I want to select all the tags in it using jquery.

推荐答案

不允许加载外部资源,除非在您要解析的页面中显示标题:

You can't as jquery doesn't allow you to load external resources, unless in the page you want to parse is present the header:

header('Access-Control-Allow-Origin: http://thesitewhereyourjscodeishosted');

如果无法设置,您可以使用PHP:

If you can't set it, you could use PHP:

<script>
var website = <?php echo file_get_contents("http://websitetoload"); ?>;
</script>

这篇关于如何加载网站HTML使用jquery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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