-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
80 lines (69 loc) · 2.71 KB
/
Copy pathindex.php
File metadata and controls
80 lines (69 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
set_time_limit(999);
require('phpQuery-onefile.php');
$link = mysqli_connect("localhost", "mysql", "mysql", "host1513206_parser");
if (!$link) print("Ошибка: Невозможно подключиться к MySQL " . mysqli_connect_error());
function g($url){
$url = trim($url);
if (!$html = file_get_contents($url)) file_put_contents('error.txt', $url."\n", FILE_APPEND | LOCK_EX);
$html = mb_convert_encoding ($html, 'HTML-ENTITIES', "UTF-8");
$dom = phpQuery::newDocument( $html );
$out = array();
$breadc = "";
foreach($dom->find(".breadcrumbs li") as $key => $value){
$pq = pq($value);
$breadc .= $pq->find("span")->text() . "/";
}
$images = array();
foreach($dom->find(".product-zoom__slider img") as $key => $value){
$pq = pq($value);
array_push ($images, $pq->attr('data-imagefull'));
}
$title = $dom->find("h1.product__name")->text();
$price = wipe($dom->find(".product__price-price:not(.product__price_black)")->text());
$price_opt = wipe($dom->find(".product__price_black")->text());
$article = $dom->find("#copytext")->text();
$quantity = $dom->find(".SKU_MAX_QTY")->attr('value');
$description = $dom->find(".product-info__content.product-description")->html();
$images = json_encode($images);
$out = array(
'title' => $title,
'breadcrumbs' => $breadc,
'price' => $price,
'price_opt' => $price_opt,
'article' => $article,
'quantity' => $quantity,
'images' => $images,
'description' => $description,
);
// return $out['title'];
return $out;
}
function wipe($text){
return str_replace(array(" ", "р", "."), "", $text);
}
function getsql($data){
$sql = 'INSERT INTO results SET
title = "' . mysqli_real_escape_string($GLOBALS['link'], $data['title']) . '",
breadcrumbs = "' . mysqli_real_escape_string($GLOBALS['link'], $data['breadcrumbs']) . '",
price = "' . mysqli_real_escape_string($GLOBALS['link'], $data['price']) . '",
price_opt = "' . mysqli_real_escape_string($GLOBALS['link'], $data['price_opt']) . '",
article = "' . mysqli_real_escape_string($GLOBALS['link'], $data['article']) . '",
quantity = "' . mysqli_real_escape_string($GLOBALS['link'], $data['quantity']) . '",
images = "' . mysqli_real_escape_string($GLOBALS['link'], $data['images']) . '",
description = "' . mysqli_real_escape_string($GLOBALS['link'], $data['description']) . '"' ;
return $sql;
}
$f = file('urls.txt');
$br="";
foreach ($f as $key => $value) {
if ( mysqli_query($link, getsql( g($value) )) ) echo ".";
// var_dump(getsql( g($value) ));
usleep(rand(100000, 340000));
echo " ";
if (++$br == 10){
echo ("<br>"); $br=0;
}
set_time_limit(900);
}
// fclose($f);