php爬取html內容

1、curl方式獲取

<?php

$a = 'http://www.888.com/123.html';
$ch = curl_init($a);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');
$f = curl_exec($ch);
echo $f;

地址:https://gitee.com/jianwicn/mixed/raw/master/taobao

2、file_get_contents獲取

<?php

$a = 'http://www.888.com/123.html';
$opts = array(
    'http'=>array(
        'method'=>"GET",
        'header'=>
            "Accept-language: zh-cn\r\n" .
            "User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; 4399Box.560; .NET4.0C; .NET4.0E)" .
            "Accept: *//*"
    )
);
$ctx = stream_context_create($opts);
$x = file_get_contents($a,false,$ctx);
echo $x;

下載地址:https://gitee.com/jianwicn/mixed/raw/master/file_get_contents

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章