Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/im-machakata/cctv-direct
https://github.com/im-machakata/cctv-direct
Last synced: 5 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/im-machakata/cctv-direct
- Owner: im-machakata
- Created: 2023-06-26T12:42:34.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-26T16:51:04.000Z (over 1 year ago)
- Last Synced: 2024-11-09T09:26:32.311Z (2 months ago)
- Language: HTML
- Size: 26.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: .github/README.md
Awesome Lists containing this project
README
# PHP Data Miner
Fetches data from a certain website.
## Installation
Clone or Download the code and install the dependencies using Composer
```composer install```## Usage
Include the autoload file and setup and headers.
```php
use CctvDirect\Scrapper;include __DIR__ . "/vendor/autoload.php";
header('Content-Type: application/json');
```## # localhost scrapping
The following scrapes data from the file in the bin folder
```php
$results = array();
$scrapper = new Scrapper();
$scrapper->scrape('http://localhost/bin/dahua-analog-hd-cctv-cameras.htm');// ? localhost demo scrapping
$collection = $scrapper->collection;
$results = array(
'title' => $collection->getTitle(),
'category_slug' => $collection->getCategorySlug(),
'products' => $collection->getProducts(),// 'collections' => $collection->getCollections(),
);
// ? print results
echo json_encode($results, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
```## # live scrapping
In this example, we get the collections from the file in the bin, then scrap products from the live site.
```php
$collections = $scrapper->collection->getCollections();foreach ($collections as $collectionUrl) {
$scrapper->scrape($collectionUrl);
$results[$scrapper->collection->getCategorySlug()] = array(
'title' => $scrapper->collection->getTitle(),
'products' => $scrapper->collection->getProducts()
);
}
```