Home >Web Front-end >HTML Tutorial >curl, fsocketopen, socket three functions to capture html page_html/css_WEB-ITnose
(1) php - curl
<?php $ch_article = curl_init(); $url = 'www.baidu.com'; curl_setopt($ch_article, CURLOPT_URL, $url); curl_setopt($ch_article, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch_article, CURLOPT_HEADER, 0); $article_output = curl_exec($ch_article); curl_close($ch_article); echo $article_output;?>
<?php$fp = fsockopen("www.baidu.com", 80, $errno, $errstr, 30);$out = "GET / HTTP/1.1\r\n";$out .= "Host: www.baidu.com\r\n";$out .= "Connection: Close\r\n\r\n";fwrite($fp, $out);while (!feof($fp)) { echo fgets($fp, 128);}fclose($fp);?>
<?php$url='www.baidu.com';$Port = 80;$host_ip = gethostbyname('www.baidu.com');$Header .= trim('Host:www.baidu.com')."\r\n";$Header .= trim('Connection: Close')."\r\n";$method = 'GET';$Request = $method." " . '/' . " HTTP/1.1\r\n";$Request .= $Header;$Request .= "\r\n";$sockHttp = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);$resSockHttp = socket_connect($sockHttp, $host_ip, $Port);socket_write($sockHttp, $Request, strlen($Request));$Response = '';while ($Read_data = socket_read($sockHttp, 4096)){ $Response .= $Read_data;}socket_close($sockHttp);echo $Response;?>
Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.