// Initialize goutte $goutte = new Goutte\Client(); // Get Database $db = new Db(); $loginUrl = 'http://www.colorfive.com/sign-in'; $crawler = $goutte->request('GET', $loginUrl); print_r($crawler->html()); exit; // Default Status code $status_code = 200; $count = 1; $data = $db->query("SELECT url from product_urls WHERE source='numberonewholesales'"); $url = ''; foreach ($data as $value) { $url = $value['url']; $data = getProductData($goutte, $url, $db); } function getProductData($goutte, $url, $db) { $crawler = $goutte->request('GET', $url); $status_code = $goutte->getResponse()->getStatus(); $data = array(); if ($status_code == 200) { $attribs = array(); $domSelector = '//*[@class="productInfoName"]'; $attribs['title'] = $data = $crawler->filterXPath($domSelector)->each(function ($node) { return $node->text(); }); $domSelector = '//*[@id="zoom1-big"]'; $attribs['mainImage'] = $data = $crawler->filterXPath($domSelector)->each(function ($node) { return $node->attr('href');
$tempUrls = $crawler->filterXPath($domSelector)->each(function ($node) { return $node->attr('href'); }); foreach ($tempUrls as $url) { if ($url != '#') { array_push($urls, $url); } } if (count($tempUrls) < 2 || count($urls) >= $tProducts) { $status = 0; } $count++; } foreach ($urls as $url) { $db->query("INSERT INTO product_urls(url, url_hash, source,status)\n\t\t \t\t\tVALUES(:url, :url_hash, :source, :status)\n\t\t \t\t\tON DUPLICATE KEY UPDATE updated_on = NOW();", array("url" => 'https://www.lashowroom.com' . $url, "url_hash" => hash('ripemd160', 'https://www.lashowroom.com' . $url), "source" => "lashowroom", "status" => 1)); $product = getProductData($goutte, $url); $temp = $db->query("SELECT 1 FROM products_data WHERE url_hash = '" . hash('ripemd160', 'https://www.lashowroom.com' . $url) . "'"); if (count($temp) == 0) { /*Insert Product*/ $db->query("INSERT INTO products_data(url,url_hash,source,data,category,subcategory,status) \n\t\t \t\t\tVALUES(:url,:url_hash,:source,:data,:category,:subcategory,:status);", array("url" => 'https://www.lashowroom.com' . $url, "url_hash" => hash('ripemd160', 'https://www.lashowroom.com' . $url), "source" => "lashowroom", "data" => json_encode($product), "category" => $product['category'], "subcategory" => '', "status" => 1)); } else { /*Insert Product*/ $db->query("UPDATE products_data SET `data`= :data, `status`= :status,`updated_on`= NOW() WHERE url_hash = :url_hash;", array("data" => json_encode($product), "status" => 1, "url_hash" => hash('ripemd160', 'https://www.lashowroom.com' . $url))); echo "Updated" . PHP_EOL; } goToSleep(); } function getProductData($goutte, $url) { $crawler = $goutte->request('GET', $url); $status_code = $goutte->getResponse()->getStatus();
<?php require_once explode("wp-content", __FILE__)[0] . "wp-load.php"; require_once "functions.php"; if (is_ajax()) { if (isset($_POST["action"]) && !empty($_POST["action"])) { //Checks if action value exists $action = $_POST["action"]; switch ($action) { //Switch case for value of action case "getproductdata": getProductData(); break; case "emptyandaddtocart": emptyAndAddToCart(); break; case "addtocartandupdatetotals": AddToCartAndUpdateTotals(); break; case "checkcartandupdatetotals": CheckCartAndUpdateTotals(); break; } } } //Function to check if the request is an AJAX request function is_ajax() { return isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest'; } function getProductData()
$data = getLinkEndPoints($goutte, $baseURL . $leggingsEndpoint); // 626c58c29f34cc92e0f8cfbaad456ccedf3cbe4b if ($data['status'] == 200) { foreach ($data['urls'] as $key => $value) { foreach ($value[0] as $val) { $insert = $db->query("INSERT IGNORE INTO master_urls(url, url_hash, source, category, subcategory, status) \n\n\t\t\t\t\t\t\t\t\t\t\tVALUES(:url, :url_hash, :source, :category, :subcategory, :status)", array("url" => $val[0], "url_hash" => hash('ripemd160', $val[0]), "source" => "sngapparelinc", "category" => $key, "subcategory" => $val[1], "status" => 1)); // Get Product URLS $productUrls = getLink($goutte, $val[0]); $sleep_time = rand(2 * 1000000, 3 * 1000000); echo "\tSleeping for " . number_format($sleep_time / 1000000, 2) . " sec\n"; usleep($sleep_time); foreach ($productUrls as $url) { // // Insert Product URLs $db->query("INSERT IGNORE INTO product_urls(url, url_hash, source,status)\n\n\t\t \t\t\tVALUES(:url, :url_hash, :source, :status)", array("url" => $url, "url_hash" => hash('ripemd160', $url), "source" => "sngapparelinc", "status" => 1)); // Get Data $data = getProductData($goutte, $url); $insert = $db->query("INSERT INTO products_data(url, url_hash, source, data, category, subcategory, status) \n\n\t\t \t\t\tVALUES(:url, :url_hash, :source, :data, :category, :subcategory, :status)\n\n\t\t \t\t\tON DUPLICATE KEY UPDATE updated_on = NOW();\n\n\t\t \t\t\t", array("url" => $url, "url_hash" => hash('ripemd160', $url), "source" => "sngapparelinc", "data" => json_encode($data), "category" => $key, "subcategory" => $val[1], "status" => 1)); // echo $url."\n"; // print_r($insert); $sql = "UPDATE products_data SET status=1 WHERE url_hash='" . hash('ripemd160', $url) . "'"; $db->query($sql); } } } } function getUrlFromArray($data) { if (!is_array($data)) { // nothing to do if it's not an array return array($data); }
<?php // Include config and initiate include_once __DIR__ . '/../config/default_config.php'; includeMyFiles(); $goutte = new Goutte\Client(); // Get Database $db = new Db(); $db->query("UPDATE products_data SET status=0 WHERE source='lashowroom'"); $url = 'https://www.lashowroom.com/login?previous=/wholesalefashionistas/browse/category/3/srd/small/70/1'; $crawler = $goutte->request('GET', $url); $form = $crawler->selectButton('Log In')->form(); // exit; $crawler = $goutte->submit($form, array('login_id' => '*****@*****.**', 'login_key' => 'uplp')); $product = getProductData($goutte, 'https://www.lashowroom.com/wholesalefashionistas/item/1215'); print_r($product); function getProductData($goutte, $url) { $crawler = $goutte->request('GET', $url); $status_code = $goutte->getResponse()->getStatus(); $data = array(); $result = array(); if ($status_code == 200) { $filterNav = '//*[@class="item-detail-header"]/p/a'; $catStruct = $crawler->filterXPath($filterNav)->each(function ($node) { return $node->html(); }); foreach ($catStruct as $key => $catVal) { $catStruct[$key] = trim(str_replace(' ', '', $catVal)); } $result['category'] = $catStruct[1];
<?php session_start(); error_reporting(0); require_once 'lib/config.php'; require_once 'lib/functions.php'; $products = getProductData($_SESSION['cart']); ?> <!doctype html> <html lang="ru"> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="css/style.min.css"> <link rel="stylesheet" href="css/jquery-ui.min.css"> <link rel="stylesheet" href="css/jquery-ui.theme.min.css"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Корзина</title> <script src="https://cdnjs.cloudflare.com/ajax/libs/prefixfree/1.0.7/prefixfree.min.js"></script> <script src="js/jquery-2.1.3.min.js"></script> <script src="js/jquery-ui.min.js"></script> <script src="js/main.min.js"></script> </head> <body> <?php include 'lib/header.inc.php'; ?> <div class="wrap"> <?php if ($products) { ?> <h3>Ваши покупки</h3>
<?php //============================ CYCLE PRODUCT LIST SECTION ======================================== $data = getProductData($module['productItems']); ?> <div class="main-container"> <section> <div class="cycle-slideshow" data-cycle-loader=true data-cycle-fx="flipHorz" data-cycle-timeout="3000" data-cycle-pause-on-hover="true" data-cycle-slides="> div"> <?php foreach ($data['cycle_products'] as $item) { ?> <div class="slide-item"> <div id="slide-img"> <a title="<?php echo $item['keyword']; ?> " href="<?php echo $item['permalink']; ?> "> <img src="<?php echo $item['image_url']; ?> " alt="<?php echo $item['keyword']; ?>
<th>Адрес</th> <th>Транспортная компания</th> <th>Товар</th> <th>Общая сумма</th> <th>Дата</th> <th>Время</th> <th>Выполнение</th> </tr> </thead> <?php // var_dump($orders); foreach ($orders as $key) { $products = unserialize($key['product']); // var_dump($products); // var_dump($products); $productData = getProductData($products); ?> <tr <?php if ($key['complite'] == 1) { echo "class='complite'"; } ?> > <td><?php echo $key['name']; ?> </td> <td><?php echo $key['mail'];