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

在尝试使用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 07: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部