Maison  >  Questions et réponses  >  le corps du texte

php如何从一个网址中获取到他所对应页面的html源代码?

我用file_get_contents($url);这个方法不行
`$url = $_POST['url'];
$ch = curl_init();
$timeout = 3;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);
echo $contents;
exit;`
url是在前端输入的,我试过了,输入www.baidu.com,显示的仍是百度的界面,而不是他的html源代码

phpcn_u238phpcn_u2382744 Il y a quelques jours1034

répondre à tous(2)je répondrai

  • 数据分析师

    数据分析师2017-10-01 00:53:33

    Comment php obtient-il le code source html de sa page correspondante à partir d'une URL ? - Questions et réponses sur le site Web PHP chinois - Comment php obtient-il le code source html de sa page correspondante à partir d'une URL ? - Questions et réponses sur le site Web PHP chinois

    Jetez un oeil autour de vous , Étudiez-le.

    répondre
    0
  • 阿神

    阿神2017-03-17 14:25:31

    <?php
     $pagecontent = file_get_contents("http://www.php.cn"); 
     echo htmlspecialchars($pagecontent);//htmlentities 或者htmlspecialchars
     ?>

    这样就好了吧  你试试

    répondre
    0
  • Annulerrépondre