core/parcer/tk.php

112 lines
3.9 KiB
PHP
Raw Permalink Normal View History

2023-01-07 18:55:55 +05:00
<?php
ini_set('display_errors', 1 );
function leopak ($text) {
$old1 = array("https://market.leopak.ru/");
$new1 = array("/");
$text = str_replace($old1, $new1, $text);
return $text;
}
require_once '/home/www/tk-ligat.ru/parcer/mysql7.php';
function add_link($html, $url_id, $db){
preg_match_all("/<[Aa][\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>/", $html, $matches);
$urls = $matches[1]; // Берём то место, где сама ссылка (благодаря группирующим скобкам в регулярном выражении)
/* Выводим все ссылки */
for ($j = 0; $j < count($urls); $j++){
unset($a);
$a['url_id']=$url_id;
$a['link']=$urls[$j];
$c=$db->count_sql('donorLinks', $a);
$a['t']=time();
if ($c==0 && $a['url_id'] && $a['link'])$db->add('donorLinks', $a);
}
}
$db = new MySQL('tk-ligat', 'MYSQL', 'localhost', 'admin', '32143214');
//$db->free_sql('CREATE TABLE `donorLinks` ( `id` INTEGER PRIMARY KEY NOT NULL, `url_id` INTEGER, `link` TEXT, `t` TEXT, `check` INTEGER DEFAULT 1, `html` TEXT )');
function findtxt($txt, $str){
$pos1 = stripos($txt, $str);
if ($pos1 === false) return 0;
else
return 1;
}
function get_page($link){
$agent = 'Mozilla/5.0 (compatible; YandexBot/3.0)';
echo $link . "\n\r";
if (findtxt($link, 'ruhtttp')==0){
$ch = curl_init($link);
curl_setopt($ch, CURLOPT_REFERER, 'https://www.samsonopt.ru');
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$dir = dirname(__FILE__);
$config['cookie_file'] = $dir . '/cookies/' . md5(@$_SERVER['REMOTE_ADDR']) . '.txt';
curl_setopt($ch, CURLOPT_COOKIEFILE, $config['cookie_file']);
curl_setopt($ch, CURLOPT_COOKIEJAR, $config['cookie_file']);
curl_setopt($ch, CURLOPT_COOKIE, "PMBC=96152e8e9a0168a731539c5e52c6b39a; PHPSESSID=jl0i13pn3157qca807jgp0jqa7; ServerName=WoW+Circle+3.3.5a+x5; serverId=1");
// curl_setopt($ch, CURLOPT_PROXY, 'localhost:9050'); // Use if proxy have username and password
// curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
$response_data = curl_exec($ch);
if (curl_errno($ch) > 0) {
2023-05-03 14:51:58 +05:00
// die('Ошибка curl: ' . curl_error($ch));
2023-01-07 18:55:55 +05:00
}
curl_close($ch);
return $response_data;
}
}
$partnersURL = $db-> free_sql('SELECT * FROM `partnersSites`');
$count = count($partnersURL);
for ( $i=0; $i<$count; $i++ ){
unset( $html );
$html = get_page ( $partnersURL[$i]['url'] );
add_link($html, $partnersURL[$i]['id'], $db);
}
//add_link($response_data, 1, $db);
$db->free_sql('UPDATE donorLinks SET `check`=0 WHERE link LIKE "%https://%"');
$LinkList = $db -> free_sql( 'SELECT * FROM `donorLinks` WHERE `html` IS NULL ORDER BY RAND() LIMIT 5000');
$count = count( $LinkList );
for ($i=0; $i<$count; $i++){
// sleep(1);
// Получаем адрес партнера
unset($a);
unset($html);
$a['id'] = $LinkList[$i]['url_id'];
$url = $db -> get_val( 'partnersSites', $a, 'url' ) . $LinkList[$i]['link'];
$html=get_page ( $url );
if ($html){
// $html = iconv('windows-1251//IGNORE', 'utf-8//IGNORE', $html);
$file = '/home/yuec/www/scripts/' . $LinkList[$i]['id'] . '.html';
// file_put_contents($file, $html);
add_link($html, $LinkList[$i]['url_id'], $db);
$html = base64_encode ( gzcompress ( $html, 9) );
$sql='UPDATE `donorLinks` SET `html` = "' . $html . '" WHERE `id`=' . $LinkList[$i]['id'];
$db->free_sql($sql);
}
//print_r ( $db->free_sql('SELECT COUNT(*) FROM `donorLinks`WHERE `link` LIKE "%CODE=%" AND `html` IS NULL') );
}
//$html = file_get_contents('https://www.samsonopt.ru/zakaz/index.php?ID=218377');
//echo $html;
2023-05-03 14:51:58 +05:00
//exec ('php tk.php &');
//exec ('php tk.php &');
2023-01-07 18:55:55 +05:00
?>