Last active
June 14, 2024 22:16
-
-
Save ohid/ee0da594226f825a328412c2b6f06f18 to your computer and use it in GitHub Desktop.
Scrap a specific site and get sales data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$pages = [ | |
'https://templatish.com/template/top-10-elementor-image-hover-effects/?layout=profile', | |
'https://templatish.com/template/elementor-advanced-slider-with-card-carousel/?layout=profile', | |
'https://templatish.com/template/elementor-animated-side-menu/?layout=profile', | |
'https://templatish.com/template/elementor-playing-cards-animated-lightbox/?layout=profile', | |
'https://templatish.com/template/elementor-team-member-slider-with-reveal-animation/?layout=profile', | |
'https://templatish.com/template/elementor-table-image-hover-effect/?layout=profile', | |
'https://templatish.com/template/elementor-stagger-menu/?layout=profile', | |
'https://templatish.com/template/elementor-stacked-card-scrolling-effect/?layout=profile', | |
'https://templatish.com/template/elementor-portfolio-page-with-text-reveal-effect/?layout=profile', | |
'https://templatish.com/template/elementor-image-hover-effect-stagger-animation/?layout=profile', | |
'https://templatish.com/template/elementor-full-width-menu-with-image-hover-effect/?layout=profile', | |
'https://templatish.com/template/elementor-image-gallery-with-animated-lightbox/?layout=profile', | |
'https://templatish.com/template/elementor-image-orbit-hover-effect/?layout=profile', | |
'https://templatish.com/template/elementor-auto-sliding-image/?layout=profile', | |
'https://templatish.com/template/elementor-icon-navigation-menu-bar/?layout=profile', | |
'https://templatish.com/template/elementor-stunning-contact-page/?layout=profile', | |
'https://templatish.com/template/elementor-repeat-image-hover-effect/?layout=profile', | |
'https://templatish.com/template/elementor-animated-circle-background-14-templates/?layout=profile', | |
'https://templatish.com/template/elementor-portfolio-live-preview-box/?layout=profile', | |
'https://templatish.com/template/elementor-wow-animation/?layout=profile', | |
'https://templatish.com/template/elementor-3d-360-featured-product-view/?layout=profile', | |
'https://templatish.com/template/elementor-blurry-card-hover-effect/?layout=profile', | |
'https://templatish.com/template/elementor-animating-video-popup/?layout=profile', | |
'https://templatish.com/template/elementor-3d-cube-slider/?layout=profile', | |
'https://templatish.com/template/elementor-post-cards/?layout=profile', | |
'https://templatish.com/template/elementor-card-carousel/?layout=profile', | |
'https://templatish.com/template/elementor-unique-slider/?layout=profile', | |
'https://templatish.com/template/elementor-full-width-menu-header/?layout=profile', | |
'https://templatish.com/template/elementor-app-landing-page-banner/?layout=profile', | |
'https://templatish.com/template/elementor-shaking-image-hover-effect/?layout=profile', | |
'https://templatish.com/template/elementor-bubble-overlay-effect/?layout=profile', | |
'https://templatish.com/template/elementor-angle-image-hover-effect/?layout=profile', | |
'https://templatish.com/template/elementor-auto-sliding-cards/?layout=profile', | |
'https://templatish.com/template/elementor-sidebar-header/?layout=profile', | |
]; | |
$total_sales = 0; | |
$total_sales_value = 0; | |
foreach( $pages as $page_url ) { | |
$page_data = file_get_contents( $page_url ); | |
$dom = new \DOMDocument; | |
libxml_use_internal_errors(true); // Disable libxml errors | |
$dom->loadHTML($page_data); | |
libxml_clear_errors(); // Clear any errors | |
$xpath = new \DOMXPath($dom); | |
$query = "//div[contains(@class, 'sp-sales')]//p//strong"; | |
$nodes = $xpath->query($query); | |
foreach ($nodes as $node) { | |
$sales = intval( $node->textContent ); | |
} | |
$query = "//div[contains(@class, 'sp-price')]//span[contains(@class, 'tooltip')]"; | |
$nodes = $xpath->query($query); | |
foreach ($nodes as $node) { | |
$price = $node->textContent; | |
$price = floatval(preg_replace('/[^0-9.]/', '', $price)); | |
} | |
$item_sales_value = $sales * $price; | |
$total_sales = $total_sales + $sales; | |
$total_sales_value = $total_sales_value + $item_sales_value; | |
} | |
print( 'Total sales: ' . $total_sales ); | |
print( 'Total sales value: ' . $total_sales_value ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment