如何通过php获取完整的网页html


How to get full html of web page via php

我想通过php代码获得任何网页的所有数据或仅内容。如果有人知道这一点,请帮助我如何获得这个gole

感谢提前

下面的代码不可能做到吗?

file_get_contents("http://www.domain.tld/page.html");

将此函数与URL一起调用以获得html响应。

    <?php
        function curl($url){
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
            curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
            curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0');
            $data = curl_exec($ch);
            curl_close($ch);
            return $data;
        }
        ?>
echo curl('http://www.google.com'); //your url..

运行此代码时,PHP将为您提供整个页面。。。如果你打算废掉这一页,请在这里阅读。

请阅读代码中设置的各种cURL参数以及其他各种参数。