core/parcer/desnet.php

71 lines
3.1 KiB
PHP
Raw Permalink Normal View History

2023-02-08 16:59:59 +05:00
<?php
$_SERVER['SERVER_NAME']='tk-ligat.ru';
require_once('/home/cloud/core/set/tk-ligat.ru.php');
require_once('/home/cloud/core/api/php/db.php');
require_once('/home/cloud/core/api/php/json.php');
function leopak ($text) {
$old1 = array("\\");
$new1 = array("/");
$text = str_replace($old1, $new1, $text);
return $text;
}
/* ищет str в txt если находит, возвращает единичку */
function findtxt($txt, $str){
$pos1 = stripos($txt, $str);
if ($pos1 === false) return 0;
else
return 1;
}
function add_link($html){
preg_match_all("/<[Aa][\s]{1}[^>]*[Hh][Rr][Ee][Ff][^=]*=[ '\"\s]*([^ \"'>\s#]+)[^>]*>/", $html, $matches);
$urls = $matches[1]; // Берём то место, где сама ссылка (благодаря группирующим скобкам в регулярном выражении)
/* Выводим все ссылки */
for ($j = 0; $j < count($urls); $j++){
$link=$urls[$j];
if (findtxt($link, 'https://www.deznet.ru')==0) $link = 'https://www.deznet.ru' . leopak($link);
$id=DB::getValue("SELECT `id` FROM `sm2` WHERE `link` LIKE '%" . $link . "' LIMIT 1");
if (!$id)DB::add("INSERT INTO `sm2` (`link`, `status`) VALUES (?, ?)", array($link, 1));
}
}
function get_page($link){
$agent = 'Mozilla/5.0 (compatible; YandexBot/3.0)';
$ch = curl_init($link);
//curl_setopt($ch, CURLOPT_REFERER, 'https://www.samsonopt.ru');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 20); //timeout in seconds
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) {
die('Ошибка curl: ' . curl_error($ch));
}
curl_close($ch);
return $response_data;
}
//exec ("php /home/cloud/core/parcer/r2.php");
//DELETE FROM table WHERE id NOT IN (SELECT max(id) FROM table GROUP BY name HAVING count(id)>1)
//DELETE FROM `sm` WHERE `id` NOT IN (SELECT max(`id`) FROM `sm` GROUP BY `link` HAVING count(`id`)>1)`status`=1 AND
$LinkList = DB::getAll( 'SELECT * FROM `sm2` WHERE `link` NOT LIKE "%.jpg" ORDER BY RAND() LIMIT 300');
for ($i=0; $i<count( $LinkList ); $i++){
if (findtxt($LinkList[$i]['link'], 'https://www.deznet.ru')==0) $LinkList[$i]['link']= 'https://www.deznet.ru' . $LinkList[$i]['link'];
$html=get_page($LinkList[$i]['link']);
if ($html) {
add_link($html);
DB::set("UPDATE `sm2` SET `status`=1 WHERE `id`=?", $LinkList[$i]['id']);
}
unset($html);
//sleep(3);
}
?>