Php ile Bot Yapımı Part 2


php ile bot yapımının 2. videosu

Kaynak Dosyaları:

index.php

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<?php
include 'bot.php';
Bot("http://www.sosyalradar.com");
?>
</body>
</html>

bot.php

<?php
function Bot($url) {
$ac = Curl($url);
preg_match('/<ul class="uk-pagination uk-grid-margin" role="navigation">(.*?)<\/ul>/', $ac, $sayfa);
preg_match_all('/<a href="(.*?)">(.*?)<\/a>/', $sayfa[1], $sayfalama);
$say = count($sayfalama[2]) - 2;
$sayfa_sayisi = $sayfalama[2][$say];
for ($i = 1; $i <= $sayfa_sayisi; $i++) {
if ($i > 1) {
$sayfa = "/page/" . $i;
} else {
$sayfa = "";
}
$ac2 = Curl($url . $sayfa);
preg_match_all('/<h2 class="uk-article-title uk-margin-small-top uk-h2" itemprop="headline">(.*?)<\/h2>/', $ac2, $link);
foreach ($link[1] as $ln) {
preg_match('/<a href="(.*?)" title="(.*?)" rel="bookmark">(.*?)<\/a>/', $ln, $alan);
//echo $alan[1] . "<br>";
Detay($alan[1]);
}
}
}
function Detay($url) {
$ac = Curl($url);
preg_match('/<h1(.*?)>(.*?)<\/h1>/', $ac, $title);
preg_match('/<time datetime="(.*?)" itemprop="datePublished" class="uk-text-muted">(.*?)<\/time>/', $ac, $tarih);
preg_match('/<img class="alignnone(.*?)" src="(.*?)"(.*?)\/>/', $ac, $resim);
echo $title[2] . "<br>";
echo $tarih[2] . "<br>";
echo $resim[2] . "<br>";
}
function Curl($url, $proxy = NULL) {
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_HEADER => false,
CURLOPT_ENCODING => "",
CURLOPT_AUTOREFERER => true,
CURLOPT_CONNECTTIMEOUT => 30,
CURLOPT_TIMEOUT => 30,
CURLOPT_MAXREDIRS => 10,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false
);
$ch = curl_init($url);
curl_setopt_array($ch, $options);
$content = curl_exec($ch);
$err = curl_errno($ch);
$errmsg = curl_error($ch);
$header = curl_getinfo($ch);
curl_close($ch);
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
return str_replace(array("\n", "\r", "\t"), NULL, $header['content']);
}

kaynak dosyaları: http://goo.gl/05gggF