Category : General Programming Toggle

[PHP] Basic Web Crawling – 1

cURL
header(‘Content-Type: text/xml’);
$curl = curl_init();
$timeout = 5; // zero is infinity
$url = ‘http://feedproxy.feedburner.com/jquery/’;
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $timeout);
print curl_exec($curl);
curl_close($curl);

cURL Example
$url = ‘https://graph.facebook.com/btaylor’;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$g = curl_exec($ch);
curl_close($ch);
echo $g;

file_get_contents
header(‘Content-Type: text/xml’);
print file_get_contents(‘http://jquery.com/blog/feed’);

fscock
$url1=”www.webprogram.co.kr”;
$url2=”GET / HTTP/1.0\r\nHost: www.webprogram.co.kr\r\n\r\n”;
$fp = fsockopen ($url1, 80, $errno, $errstr,30);
if (!$fp) {
echo “…. $errstr ($errno)
n”;
} else {
fputs($fp, $url2);
while(!feof($fp)) {
echo fgets($fp,128);
}
fclose ($fp);
}

ShutDown