dsj1961061 2013-11-08 17:08
浏览 44
已采纳

如何使用PHP获取任何网站的HTML源代码? [重复]

This question already has an answer here:

I'm trying to get the HTML source from a website using PHP, I've tried the following code and it works correctly for google.com and other websites, but it does not work for facebook.com

What am I missing?

<?php
    $curl_handle=curl_init();
    curl_setopt($curl_handle, CURLOPT_URL,'www.facebook.com');
    curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
    curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($curl_handle, CURLOPT_USERAGENT, 'Mozilla/5.0');
    $query = curl_exec($curl_handle);
    curl_close($curl_handle);
    $query =  htmlentities($query);
    echo $query;
?>
</div>
  • 写回答

1条回答 默认 最新

  • duanliao5995 2013-11-08 17:09
    关注

    That is because facebook runs on HTTPS (SSL Protocol) . Add this to your existing cURL parameters

    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl_handle, CURLOPT_SSL_VERIFYHOST, false);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法