【问题标题】:How to get html source code from external url如何从外部 url 获取 html 源代码
【发布时间】:2011-07-14 10:14:06
【问题描述】:

如何从外部网页获取 html 源代码?

类似:getHtml('http://google.com');

我尝试使用:$("#frame").contents().find("html"); 获取 iframe 的内容,但如果在我的情况下网页没有 html 标签,则只有 1 行文本。我不能用 php file_get_contents() 来做,因为它不保留会话数据。

【问题讨论】:

标签: javascript jquery


【解决方案1】:

我认为使用带有 setRequestHeader('content-type','xml/text') 的 javascript xmlhttprequest 和你需要的 url 它将 responseText 作为页面的 html 返回

【讨论】:

  • 这个答案看起来不正确。如果你喜欢,你可以删除它。这可能是一个好主意,因为我认为您现在的声誉不好。如果您删除它,它可能会回到原来的状态。
【解决方案2】:

使用 javascript,出于安全原因,许多浏览器都不允许从另一个域获取文件内容。在 php 中,你必须使用curl

对于解决方法,您可以在本地域上使用 curl 制作一个 php 脚本,然后使用 javascript 调用它。

【讨论】:

    【解决方案3】:

    跨域?没有服务器进程是不可能的。如果您在 Windows 上并且可以使用 HTA,则可以使用 iframe

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-25
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 1970-01-01
      • 2012-04-22
      • 2019-06-12
      • 1970-01-01
      相关资源
      最近更新 更多