【问题标题】:file_get_contents infinite client-side page refreshfile_get_contents 无限客户端页面刷新
【发布时间】:2013-07-28 08:28:30
【问题描述】:

我正在运行以下代码

<?php 
    echo file_get_contents('http://instagram.com/p/bivXzqRhDt');
?>

它会导致客户端浏览器 (chrome) 对同一页面执行无限自动刷新,但不显示任何内容。更改 URL 时,代码有效,但我仍然看不出为什么 file_get_contents 会刷新当前页面,除非他有某种元刷新(他没有)。

file_get_contents / curl 之后客户端出现这种无限刷新的原因是什么?

线索#1:当我查看网络调试选项卡时,我看到使用__a=1 调用了刷新。 线索#2:当我不回显内容时,它也不会刷新。

【问题讨论】:

  • 这可能是根据阻止嵌入 iframe 或复制的 JavaScript...
  • @Akam 你能详细说明一下吗?据我所知,file_get_contents 中没有启用 JS。
  • @Akam 你建议如何测试它?

标签: php javascript web web-crawler


【解决方案1】:

可能有一些 JavaScript 代码尝试重定向,因为您显示了来自您自己域的整个 Instagram 页面,curl 在这里无济于事。

尝试通过禁用浏览器中的 JavaScript 来测试它。 How to disable javascript in chrome developer tools

这应该会停止无限刷新,但如果没有 JavaScript,您将看不到 Instagram 页面内容。

我认为获得这样的行为将是非常困难的。 您可以尝试使用 iframe,但这可能也行不通。

【讨论】:

  • 我禁用了 JS,页面确实没有刷新,就像你怀疑没有加载任何内容一样。有什么方法可以识别和禁用 JS 刷新代码?
  • 从我看到的 Instagram 页面将无法使用 JavaScript。您可以尝试分析 Javascripts on the page deeply and finde the code that causes this redirects and try to bypass it. But in My opinion this will probably not be posible. Instagram use XHR requests to download additional data and from what i remember browsers dont 默认情况下支持其他域上的此请求。
  • 也许你可以使用一些无头浏览器,例如phantomjs.org,并用它来用javascript渲染instagram页面内容,这可能会奏效。
  • 这应该也有帮助Execute PhantomJS from PHP
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-06
  • 2012-02-03
  • 2017-06-19
相关资源
最近更新 更多