core/parcer/leopak.php

51 lines
1.8 KiB
PHP
Raw Normal View History

2023-02-08 16:59:59 +05:00
<?php
require_once('/home/cloud/core/api/php/db.php');
DB::$type='sqlite3';
DB::$path='/home/cloud/core/bd/tk-ligat.ru.db';
function html_to_obj($html) {
$dom = new DOMDocument();
// $dom->loadHTML($html);
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
return element_to_obj($dom->documentElement);
}
function element_to_obj($element) {
$obj = array( "tag" => $element->tagName );
foreach ($element->attributes as $attribute) {
$obj[$attribute->name] = $attribute->value;
}
foreach ($element->childNodes as $subElement) {
if ($subElement->nodeType == XML_TEXT_NODE) {
$obj["html"] = $subElement->wholeText;
}
else {
$obj["children"][] = element_to_obj($subElement);
}
}
return $obj;
}
//Собираем артикульные страницы самсона
require_once 'mysql7.php';
//$db = new MySQL('/home/yuec/www/scripts/tk.db', 'SQLITE3', '', '', '');
$db = new MySQL('tk-ligat', 'MYSQL', 'localhost', 'admin', '32143214');
$sql ="SELECT * FROM `donorLinks` WHERE `art`=" . $argv[1] . " LIMIT 1";
//echo $sql;
$db->debug=0;
$all_tovar=$db->free_sql($sql);
$count = count( $all_tovar );
for ($i=0; $i<$count; $i++){
$html = gzuncompress ( base64_decode ( $all_tovar[$i]['html'] ) );
$html = iconv('windows-1251//IGNORE', 'utf-8//IGNORE', $html);
$rest = substr($all_tovar[$i]['link'], -6);
$a = html_to_obj($html);
$massiv=$a['children'][1]['children'][1]['children'][1]['children'][0]['children'][0]['children'][3]['children'][1]['children'][1]['children'][0]['children'][0]['children'][0]['children'];
for ($i=1; $i<count($massiv); $i++){
$r = $r . '<p>' . ($massiv[$i]['children'][0]['html']) . '</p>';
}
DB::set("UPDATE `tovar` SET `txt`=? WHERE `artikul`=?", array( $r, $argv[1] ) );
}
?>