简体   繁体   English

Javascript:获取远程网页的HTML

[英]Javascript : get HTML of remote web page

I want to create a script that retrieves the HTML from several pages on a website and parse that DOM content to extract data I want. 我想创建一个脚本,从网站上的几个页面检索HTML并解析该DOM内容以提取我想要的数据。

The reason I want to do this with JavaScript is that I want to use JQuery's sizzle engine to easily parse the DOM to retrieve the information. 我想用JavaScript做这件事的原因是我想使用JQuery的sizzle引擎来轻松解析DOM以检索信息。

However with the Cross-domain policies most browsers have, I haven't found a solution yet. 但是,对于大多数浏览器的跨域策略,我还没有找到解决方案。 I stumbled across JSONP, but since that site doesn't explicitly support it, I can't use that approach. 我偶然发现了JSONP,但由于该网站没有明确支持它,我不能使用这种方法。

I also thought about using IFRAMES, but Jquery doesn't seem to be able to retrieve the content either... 我也想过使用IFRAMES,但Jquery似乎无法检索内容......

So my question really comes down to : Is there a way to get the DOM of a remote web page using javascript/ajax/jquery? 所以我的问题实际上归结为:有没有办法使用javascript / ajax / jquery获取远程网页的DOM? Are there libraries that allow this? 是否有允许这样的库?

No there is no way of read data from cross domains through client script Unless they allow it. 存在通过客户端脚本无法从跨域读取数据,除非他们允许它。

You should be looking for a solution to read the the data on the server side and then you may use it on the client side as you want. 您应该寻找一个解决方案来读取服务器端的数据,然后您可以根据需要在客户端使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM