core/parcer/robot.php

107 lines
3.4 KiB
PHP
Raw Normal View History

2023-01-07 18:55:55 +05:00
<?php
2023-02-08 16:59:59 +05:00
$_SERVER['SERVER_NAME']='tk-ligat.ru';
require_once('/home/cloud/core/set/tk-ligat.ru.php');
2023-01-07 18:55:55 +05:00
require_once('/home/cloud/core/api/php/db.php');
require_once('/home/cloud/core/api/php/json.php');
function leopak ($text) {
2023-01-25 14:20:32 +05:00
$old1 = array("https://new.yurecnt.ru");
2023-01-07 18:55:55 +05:00
$new1 = array("");
$text = str_replace($old1, $new1, $text);
return $text;
}
2023-02-08 16:59:59 +05:00
/* ищет str в txt если находит, возвращает единичку */
function findtxt($txt, $str){
$pos1 = stripos($txt, $str);
if ($pos1 === false) return 0;
else
return 1;
}
2023-01-07 18:55:55 +05:00
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++){
2023-02-08 16:59:59 +05:00
$link=$urls[$j];
if (findtxt($link, 'market.leopak.ru')==0)$link = 'https://market.leopak.ru' . $link;
$id=DB::getValue("SELECT `id` FROM `sm` WHERE `link`='" . $link . "' LIMIT 1");
if (!$id)DB::add("INSERT INTO `sm` (`link`, `status`) VALUES (?, ?)", array($link, 1));
2023-01-07 18:55:55 +05:00
}
}
2023-02-08 16:59:59 +05:00
2023-01-07 18:55:55 +05:00
function get_page($link){
2023-02-08 16:59:59 +05:00
//if (findtxt($link, 'http://market.leopak.ru')==0) $link='http://market.leopak.ru' . $link;
2023-01-07 18:55:55 +05:00
$agent = 'Mozilla/5.0 (compatible; YandexBot/3.0)';
// echo $link . "\n\r";
$ch = curl_init($link);
2023-02-08 16:59:59 +05:00
//curl_setopt($ch, CURLOPT_REFERER, 'https://www.samsonopt.ru');
2023-01-07 18:55:55 +05:00
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;
}
2023-02-08 16:59:59 +05:00
$LinkList = DB::getAll( 'SELECT * FROM `sm` WHERE `link` LIKE "https://market.leopak.ru/products/%" AND `md5` IS NULL LIMIT 10');
//echo 'SELECT * FROM `sm` WHERE `status`=1 AND `html` IS NULL ORDER BY RAND() LIMIT 2000';
2023-01-07 18:55:55 +05:00
for ($i=0; $i<count( $LinkList ); $i++){
// sleep(1);
2023-02-08 16:59:59 +05:00
$link = $LinkList[$i]['link'];
unset($html);
2023-01-07 18:55:55 +05:00
//$current=file_get_contents('../goods_sur102215_dcc93d1672486819.xml');
2023-02-08 16:59:59 +05:00
$html = get_page ( $link );
//echo $html;
2023-01-07 18:55:55 +05:00
if ($html){
add_link($html);
2023-02-08 16:59:59 +05:00
$h=base64_encode($html);
$md5=md5($h);
DB::set("UPDATE `sm` SET `html`=?, `md5`=? WHERE `id`=?", array( $h, $md5, $LinkList[$i]['id'] ) );
2023-01-07 18:55:55 +05:00
}
2023-02-08 16:59:59 +05:00
//DB::set("UPDATE `sm` SET `status`=1 WHERE `link`=?", $LinkList[$i]['link'] );
unset($html);
2023-01-07 18:55:55 +05:00
#exec ("php robot.php");
}
2023-02-08 16:59:59 +05:00
/*
5871
https://market.leopak.ru/products/026-12
9f06069de4731071e84ec6897e030756
*/
2023-01-07 18:55:55 +05:00
?>