Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array(3) {
- [0]=> array(6) {
- ["id"]=> string(2) "ID"
- ["name"]=> string(24) "Наименование"
- ["price"]=> string(8) "Цена"
- ["category"]=> string(18) "Категория"
- ["store"]=> string(14) "Магазин"
- ["currency"]=> string(12) "Валюта"
- }
- [1]=> array(6) {
- ["id"]=> int(1)
- ["name"]=> string(67) "Аккумулятор Samsung A7 2015 SM-A700 GH43-04340B ORIG100%"
- ["price"]=> string(4) "1100"
- ["category"]=> string(16) "Запчасти"
- ["store"]=> string(14) "RestartService"
- ["currency"]=> string(3) "RUB"
- }
- [2]=> array(6) {
- ["id"]=> int(2)
- ["name"]=> string(67) "Аккумулятор Samsung A5 2015 SM-A500 GH43-04337A ORIG100%"
- ["price"]=> string(4) "1100"
- ["category"]=> string(16) "Запчасти"
- ["store"]=> string(14) "RestartService"
- ["currency"]=> string(3) "RUB"
- }
- }
- ID,Наименование,Цена,Категория,Магазин,Валюта
- 1,"Аккумулятор Samsung A7 2015 SM-A700 GH43-04340B ORIG100%",1100,Запчасти,RestartService,RUB
- 2,"Аккумулятор Samsung A5 2015 SM-A500 GH43-04337A ORIG100%",1100,Запчасти,RestartService,RUB
- public function getCSV() {
- $fp = fopen('farpost_price.csv', 'w');
- foreach ($this->generateData() as $fields) {
- fputcsv($fp, $fields, ',');
- }
- var_dump($this->generateData());
- fclose($fp);
- }
- public function generateData() {
- $id = 0;
- //Проходим циклом по ссылкам продавцов
- foreach ($this->store as $key => $item) {
- //Получаем кол-во страниц
- $countPage = $this->countPage($item);
- //Проходим циклам по страницам
- for ($i = 1; $i <= $countPage; $i++) {
- //Получаем страницу
- $page = new HtmlPage(file_get_contents($item . $i), '', 'windows-1251');
- //Фильтруем текущию страницу
- $page->filter('tr.bull-item');
- //Проходим циклом по самой странице
- foreach ($page->filter('tr.bull-item') as $val) {
- $val = new HtmlPageCrawler($val);
- $this->product[] = [
- 'id' => ++$id,
- //'name' => $this->substrName($val->filter('a.bulletinLink')->text()),
- 'name' => $val->filter('a.bulletinLink')->text(),
- 'price' => $this->priceReplace($val->filter('.priceCell')->text()),
- 'category' => 'Запчасти',
- 'store' => $key,
- 'currency' => 'RUB',
- ];
- }
- }
- }
- return $this->product;
- }
- fwrite($fp, implode(',', $fields) . "rn");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement