Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=utf-8');
- include "./simple_html_dom.class.php";
- ob_implicit_flush();
- error_reporting(E_ALL);
- ini_set('display_errors', 1);
- function f() {
- flush();
- ob_flush();
- }
- function d($o) {
- echo "<pre>";
- print_r($o);
- echo "</pre>";
- f();
- }
- function htmlGet($url) {
- if (strpos($url, "/") === 0)
- $url = "https://www.miele-shop.ru" . $url;
- echo $url;
- f();
- $ch = curl_init($url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // возвращает веб-страницу
- curl_setopt($ch, CURLOPT_HEADER, 0); // не возвращает заголовки
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // переходит по редиректам
- curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.62 Safari/537.36");
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); // таймаут соединения
- curl_setopt($ch, CURLOPT_TIMEOUT, 20); // таймаут ответа
- curl_setopt($ch, CURLOPT_MAXREDIRS, 10); // останавливаться после 10-ого редиректа
- curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt');
- curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) . '/cookie.txt');
- $content = curl_exec($ch);
- curl_close($ch);
- return $content;
- }
- $index = str_get_html(htmlGet("/"));
- foreach ($index->find("#menuCatalog", 0)->find("a") as $index_a) {
- echo $index_a->plaintext . "<br>";
- f();
- $category = str_get_html(htmlGet($index_a->href));
- foreach ($category->find("#categories", 0)->find(".categoryItem") as $category_div) {
- $category_a = $category_div->find(".itemDetails", 0)->find("a", 0);
- echo " " . $category_a->plaintext . "<br>";
- f();
- $sub_category = str_get_html(htmlGet($category_a->href));
- foreach ($sub_category->find("#products", 0)->find(".productItem") as $product_div) {
- $product_a = $product_div->find(".productModel", 0)->find("a", 0);
- echo " " . $product_a->plaintext . "<br>";
- f();
- $product = str_get_html(htmlGet($product_a->href));
- $prod["title"] = $product->find("h2", 0)->plaintext;
- $prod["article"] = $product->find(".description", 0)->find("strong", 0)->plaintext;
- $prod["price"] = preg_replace("([^\d,])", "", $product->find("#infoline", 0)->find(".bigger", 0)->plaintext);
- $prod["image"] = $product->find(".imageBig", 0)->find("a", 0)->href;
- $prod["description"] = $product->find(".descriptionText", 0)->innertext;
- $chars = $product->find("#characteristicTable", 0);
- if ($chars) $prod["chars"] = $chars->outertext;
- d($prod);
- f();
- exit;
- }
- exit;
- }
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement