Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //------------------------------
- function parse_topic($topic) {
- $url='http://blogs.yandex.ru/search.xml';
- $postdata = 'text='.urlencode($topic);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER,0);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
- curl_setopt($ch, CURLOPT_COOKIEFILE, 'yacook.txt');
- curl_setopt($ch, CURLOPT_COOKIEJAR, 'yacook.txt');
- $result = curl_exec($ch);
- $result = mb_convert_encoding($result,'windows-1251');
- //echo $result;
- $uu='<td class="l-page-search-l">';
- $rez3=substr($result, strpos($result,$uu)+strlen($uu));
- $rez3=substr($rez3,0, strpos($rez3,'<td class="l-page-search-r">'));
- //echo $rez3;
- preg_match_all('/class="b-item.*?<a[^>]*?href=(["\'])([^\1>]*?)\1[^>]*?class=" Search[^>]*?>(.*?)<\/a>/ims',
- $rez3, $gets);
- return $gets;
- }
- //------------------------------
- function load_yablog_todays() {
- $url='http://blogs.yandex.ru';
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HEADER,0);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch, CURLOPT_COOKIEFILE, 'yacook.txt');
- curl_setopt($ch, CURLOPT_COOKIEJAR, 'yacook.txt');
- $result = curl_exec($ch);
- $result = mb_convert_encoding($result,'windows-1251');
- $uu='<table class="b-themes">';
- $rez3=substr($result, strpos($result,$uu)+strlen($uu));
- $rez3=substr($rez3,0, strpos($rez3,'</table>'));
- //echo $rez3;
- preg_match_all('/<a[^>]*?href=(["\'])(.*?)\1[^>]*?>(.*?)<\/a>/ims',$rez3, $gets);
- return $gets;
- }
- //-------------------------------------------
- $relstr= "
- <script type='text/javascript'>
- window.onload=function() {
- var el=document.createElement('DIV');
- el.id='inf888';
- el.num=10;
- document.body.appendChild(el);
- el.tm=setInterval( function () {
- el.innerHTML='restart after '+el.num+' s';
- el.num--;
- if (el.num==0) {
- clearInterval(el.tm);
- location.replace(location.protocol+'//'+location.hostname+location.pathname+'?step=2');
- }
- },1000);
- }</script>";
- session_start();
- echo '<html><head><title>test888</title>'.
- '<meta http-equiv="content-type" content="text/html;charset=windows-1251"/>'.
- '</head><body>';
- //-------------------------------------------
- if (!isset($_GET['step'])) {
- echo '<a href="'.$_SERVER["PHP_SELF"].'?step=1">go</a>';
- exit();
- }
- //------------------------------
- if ($_GET['step']==1) {
- $todays = load_yablog_todays();
- $els=array();
- $_SESSION['todays3']=$todays[3];
- $_SESSION['els']=$els;
- $_SESSION['step4']=0;
- echo '<pre>'.print_r($todays[3],true).'</pre>';
- echo $relstr;
- } else if ($_GET['step']==2) {
- $todays3=$_SESSION['todays3'];
- $els=$_SESSION['els'];
- $step4=$_SESSION['step4'];
- $topic=$todays3[$step4];
- $els_ftg = parse_topic($topic);
- $els_ftg4=array();
- $els_ftg4['lnk']=$els_ftg[2];
- $els_ftg4['txt']=$els_ftg[3];
- $els = array_merge_recursive($els,$els_ftg4);
- $_SESSION['els']=$els;
- $_SESSION['step4']++;
- if ($_SESSION['step4']==count($todays3)) {
- echo '<h2>final results</h2>';
- echo zpr($els);
- exit();
- }
- echo '<h2>current results</h2>';
- echo zpr($els);
- echo $relstr;
- }
- function zpr($s) {
- return '<pre>'.strip_tags(print_r($s,true)).'</pre>';
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement