Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. array(3) {
  2. [0]=> array(6) {
  3. ["id"]=> string(2) "ID"
  4. ["name"]=> string(24) "Наименование"
  5. ["price"]=> string(8) "Цена"
  6. ["category"]=> string(18) "Категория"
  7. ["store"]=> string(14) "Магазин"
  8. ["currency"]=> string(12) "Валюта"
  9. }
  10. [1]=> array(6) {
  11. ["id"]=> int(1)
  12. ["name"]=> string(67) "Аккумулятор Samsung A7 2015 SM-A700 GH43-04340B ORIG100%"
  13. ["price"]=> string(4) "1100"
  14. ["category"]=> string(16) "Запчасти"
  15. ["store"]=> string(14) "RestartService"
  16. ["currency"]=> string(3) "RUB"
  17. }
  18. [2]=> array(6) {
  19. ["id"]=> int(2)
  20. ["name"]=> string(67) "Аккумулятор Samsung A5 2015 SM-A500 GH43-04337A ORIG100%"
  21. ["price"]=> string(4) "1100"
  22. ["category"]=> string(16) "Запчасти"
  23. ["store"]=> string(14) "RestartService"
  24. ["currency"]=> string(3) "RUB"
  25. }
  26. }
  27.  
  28. ID,Наименование,Цена,Категория,Магазин,Валюта
  29. 1,"Аккумулятор Samsung A7 2015 SM-A700 GH43-04340B ORIG100%",1100,Запчасти,RestartService,RUB
  30. 2,"Аккумулятор Samsung A5 2015 SM-A500 GH43-04337A ORIG100%",1100,Запчасти,RestartService,RUB
  31.  
  32. public function getCSV() {
  33. $fp = fopen('farpost_price.csv', 'w');
  34.  
  35. foreach ($this->generateData() as $fields) {
  36.  
  37. fputcsv($fp, $fields, ',');
  38.  
  39. }
  40.  
  41. var_dump($this->generateData());
  42.  
  43. fclose($fp);
  44. }
  45. public function generateData() {
  46.  
  47. $id = 0;
  48. //Проходим циклом по ссылкам продавцов
  49. foreach ($this->store as $key => $item) {
  50. //Получаем кол-во страниц
  51. $countPage = $this->countPage($item);
  52. //Проходим циклам по страницам
  53. for ($i = 1; $i <= $countPage; $i++) {
  54. //Получаем страницу
  55. $page = new HtmlPage(file_get_contents($item . $i), '', 'windows-1251');
  56. //Фильтруем текущию страницу
  57. $page->filter('tr.bull-item');
  58.  
  59. //Проходим циклом по самой странице
  60. foreach ($page->filter('tr.bull-item') as $val) {
  61. $val = new HtmlPageCrawler($val);
  62.  
  63.  
  64. $this->product[] = [
  65. 'id' => ++$id,
  66. //'name' => $this->substrName($val->filter('a.bulletinLink')->text()),
  67. 'name' => $val->filter('a.bulletinLink')->text(),
  68. 'price' => $this->priceReplace($val->filter('.priceCell')->text()),
  69. 'category' => 'Запчасти',
  70. 'store' => $key,
  71. 'currency' => 'RUB',
  72. ];
  73. }
  74. }
  75. }
  76.  
  77. return $this->product;
  78. }
  79.  
  80. fwrite($fp, implode(',', $fields) . "rn");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement