scraping bing serp keyword ultrabook notebook tipis harga murah terbaik.
script ini digunakan untuk menscraping serp bing dengan keyword ultrabook notebook tipis harga murah terbaik.
kontes seo ultrabook notebook tipis harga murah terbaik.
langsung saja kita coba script dibawah ini..
<?php
function getPage($proxy, $url, $referer, $agent, $header, $timeout) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, ‘gzip,deflate’);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);//curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
//curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);$result[‘EXE’] = curl_exec($ch);
$result[‘INF’] = curl_getinfo($ch);
$result[‘ERR’] = curl_error($ch);curl_close($ch);
return $result;
}/* SCRAPING BING */
$result = getPage(
‘[proxy IP]:[port]’, // get a proxy from somewhere
‘http://www.bing.com/search?q=Ultrabook+Notebook+Tipis Harga+Murah+Terbaik‘,
‘http://www.bing.com/’,
‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8’,
1,
5);if (empty($result[‘ERR’])) {
preg_match_all(
‘(<div class=”sb_tlst”>.*<h3>.*<a href=”(.*)”.*>(.*)</a>.*</h3>.*</div>)siU’,
$result[‘EXE’], $matches);for ($i = 0; $i < count($matches[1]); $i++) {
// decode url
$matches[1][$i] = urldecode($matches[1][$i]);
// get rid of rds.yahoo.com redirect
//preg_match_all(‘/\*\*(http:\/\/.*$)/siU’, $matches[1][$i], $urls);
//$matches[1][$i] = $urls[0][1];
//echo “<a href='”.$matches[1][$i].”‘>”.$matches[2][$i].”</a><br>”;}
// strip tags
//for ($i = 0; $i < count($matches[2]); $i++) {
// $matches[2][$i] = strip_tags($matches[2][$i]);
// echo “<a href='”.$matches[1][$i].”‘>”.$matches[2][$i].”</a><br>”;
//}// Job’s done!
// $matches[1] array contains all URLs, and
// $matches[2] array contains all anchors
// …
} else {
// WTF? Problems?
// …
}/* END SCRAPING BING */
//echo $result[‘ERR’];
//echo $result[‘INF’];
echo $result[‘EXE’];?>
source code sumber:http://www.fromzerotoseo.com/scraping-bing-serp/
Selamat mencoba.
salam,
surya wijaya
newbie programmer