Advertisement
kervi

Untitled

Nov 1st, 2014
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.16 KB | None | 0 0
  1. $result['id'] = $id;
  2. $result['url'] = $url;
  3.  
  4. $html = file_get_html($url);
  5.  
  6. $title = $html->find('h1', 0)->plaintext;
  7. $title = explode(' (код',$title);
  8. $result['title'] = $title[0];
  9. $photos = $html->find('#thumbs a');
  10. foreach($photos as $photo){
  11. $result['photos'][] = $photo->src;
  12. }
  13.  
  14. $map = $html->find('#map', 0)->innertext;
  15. $regexp = "(\[\d*\.?\d*,\s*\d*\.?\d*\])";
  16. if(preg_match_all("/$regexp/siU", $map, $matches, PREG_SET_ORDER)) {
  17. $geo = preg_replace("/[^0-9,.]/","",$matches[0][0]);
  18. $geo = explode(',',$geo);
  19. $result['geo']['lat'] = $geo[0];
  20. $result['geo']['lon'] = $geo[1];
  21. }
  22.  
  23. $labels = $html->find('table.object-view td.label');
  24. $values = $html->find('table.object-view td.value');
  25. foreach($labels as $k=>$v){
  26. if($v->plaintext == 'Дата создания / изменения'){
  27. $date = explode(' / ',$values[$k]->plaintext);
  28. $result['created'] = strtotime($date[0]);
  29. $result['updated'] = strtotime($date[1]);
  30. }
  31. if($v->plaintext == 'Телефоны'){
  32. $phones = $values[$k]->find('strong', 0)->plaintext;
  33. $phones = explode(', ', $phones);
  34. $result['phones'] = $phones;
  35. }
  36. if($v->plaintext == 'Область'){
  37. $result['region'] = $values[$k]->plaintext;
  38. }
  39. if($v->plaintext == 'Населенный пункт'){
  40. $result['city'] = $values[$k]->plaintext;
  41. }
  42. if($v->plaintext == 'Адрес'){
  43. $result['address'] = $values[$k]->plaintext;
  44. }
  45. if($v->plaintext == 'Район города'){
  46. $area = explode(':', $values[$k]->plaintext);
  47. $result['area'] = $area;
  48. }
  49. if($v->plaintext == 'Метро'){
  50. $metro = rtrim($values[$k]->plaintext, ")");
  51. $metro = explode('( ', $metro);
  52. $metro = array_reverse($metro);
  53. $result['metro'] = $metro;
  54. }
  55. if($v->plaintext == 'Комнат всего/разд.'){
  56. $phones = $values[$k]->find('strong', 0)->plaintext;
  57. $rooms = explode(' / ', $rooms);
  58. $result['rooms_total'] = $rooms[0];
  59. $result['rooms_living'] = $rooms[1];
  60. }
  61. if($v->plaintext == 'Этаж / этажность'){
  62. $floor = explode(' / ', $values[$k]->plaintext);
  63. $result['floor'] = $floor[0];
  64. $result['floor_total'] = $floor[1];
  65. }
  66. if($v->plaintext == 'Тип дома'){
  67. $result['construction'] = $values[$k]->plaintext;
  68. }
  69. if($v->plaintext == 'Плошадь общая/жилая/кухня'){
  70. $surface = str_replace(' м²', '', $values[$k]->plaintext);
  71. $surface = explode(' / ', $surface);
  72. $result['surface_total'] = $surface[0];
  73. $result['surface_living'] = $surface[1];
  74. $result['surface_kitchen'] = $surface[2];
  75. }
  76. if($v->plaintext == 'Телефон'){
  77. $result['inner_phone'] = $values[$k]->plaintext;
  78. }
  79. if($v->plaintext == 'Полы'){
  80. $result['floors'] = $values[$k]->plaintext;
  81. }
  82. if($v->plaintext == 'Ремонт'){
  83. $result['repair'] = $values[$k]->plaintext;
  84. }
  85. if($v->plaintext == 'Год постройки'){
  86. $result['year'] = $values[$k]->plaintext;
  87. }
  88. if($v->plaintext == 'Сан/узел'){
  89. $result['toilet'] = $values[$k]->plaintext;
  90. }
  91. if($v->plaintext == 'Балкон'){
  92. $result['balcony'] = $values[$k]->plaintext;
  93. }
  94. if($v->plaintext == 'Примечания'){
  95. $result['comment'] = $values[$k]->find('div', 0)->plaintext;
  96. }
  97. if($v->plaintext == 'Условия продажи'){
  98. $result['conditions'] = $values[$k]->plaintext;
  99. }
  100. if($v->plaintext == 'Собственность'){
  101. $result['property'] = $values[$k]->plaintext;
  102. }
  103. if($v->plaintext == 'Цена'){
  104. $price = str_replace(' м²', '', $values[$k]->find('strong', 0)->plaintext);
  105.  
  106. if (strpos($price,'торг') !== false) {
  107. $result['negotiable'] = '1';
  108. } else {
  109. $result['negotiable'] = '0';
  110. }
  111. $price = explode(',',$price);
  112. $result['price_total'] = preg_replace("/[^0-9]/","",$price[0]);
  113. $result['price_metr'] = preg_replace("/[^0-9]/","",$price[1]);
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement