dowy77780 2015-02-06 14:38
浏览 63
已采纳

在尝试使用PHP cURL时无法获取Facebook页面源代码

I tried to get the source code of the following Facebook page - https://www.facebook.com/video.php?v=974372955923474&set=vb.213776828649761&type=2&theater. But it never returns the source code for the actual page, instead, it returns a source code which forms a 'Update your browser' page, it seems that I have used the wrong user-agent, but I changed the user agent to the newest version of Chrome and it still not working.

// Set curl option - following location - prevent redirects 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

    // Set curl option - retransfer
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    // Set curl option - no header
    curl_setopt($ch, CURLOPT_HEADER, false);

    // Set curl option - no body
    curl_setopt($ch, CURLOPT_NOBODY, false);

    // Set curl option - user agent
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36"); // Necessary. The server checks for a valid User-Agent.

    // Execute CURL and get the response
    $curlResponse = curl_exec($ch);
  • 写回答

1条回答 默认 最新

  • dqellle310167 2015-02-06 15:07
    关注

    I think you need to supply a login for this. I do not have a Facebook account logged on in my browser, and I need to logon. I do not see any logon information supplied in your PHP code. I think if you need to retrieve information or media from Facebook you need to have a look at the Facebook API.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算