1
1
<?php namespace Lbc \Crawler ;
2
2
3
- use Lbc \Parser \SearchResultDateTimeParser ;
4
3
use League \Url \Url ;
5
4
use Symfony \Component \DomCrawler \Crawler ;
6
5
@@ -74,7 +73,7 @@ public function getTitle()
74
73
*/
75
74
public function getPrice ()
76
75
{
77
- $ node = $ this ->node ->filter ('. price ' );
76
+ $ node = $ this ->node ->filter ('*[itemprop= price] ' );
78
77
79
78
return $ this ->getFieldValue ($ node , 0 , function ($ value ) {
80
79
return (int ) preg_replace ('/[^\d]/ ' , '' , trim ($ value ));
@@ -96,17 +95,17 @@ public function getUrl()
96
95
/**
97
96
* Return the data and time the ad was created
98
97
*
99
- * @return \Carbon\Carbon
98
+ * @return string
100
99
*/
101
100
public function getCreatedAt ()
102
101
{
103
- list ( $ date, $ time ) = $ this ->node
104
- ->filter ('.date > div ' )
105
- ->each ( function ( Crawler $ node ) {
106
- return $ node -> text ();
107
- }) ;
102
+ $ date = $ this ->node
103
+ ->filter ('*[itemprop=availabilityStarts] ' )
104
+ ->first ()
105
+ -> attr ( ' content ' )
106
+ ;
108
107
109
- return SearchResultDateTimeParser:: toDt ( $ date, $ time );
108
+ return ( new \ DateTime ( $ date))-> format ( ' Y-m-d H:m ' );
110
109
}
111
110
112
111
/**
@@ -116,13 +115,16 @@ public function getCreatedAt()
116
115
*/
117
116
public function getThumb ()
118
117
{
119
- $ node = $ this ->node ->filter ('.image-and-nb > img ' );
118
+ $ src = $ this ->node
119
+ ->filter ('.item_imagePic .lazyload[data-imgsrc] ' )
120
+ ->first ()
121
+ ->attr ('data-imgsrc ' )
122
+ ;
120
123
121
- return $ this ->getFieldValue ($ node , null , function ($ value ) {
122
- return Url::createFromUrl ($ value )
124
+ return Url::createFromUrl ($ src )
123
125
->setScheme ('http ' )
124
- ->__toString ();
125
- }, ' attr ' , ' src ' ) ;
126
+ ->__toString ()
127
+ ;
126
128
}
127
129
128
130
/**
@@ -132,7 +134,7 @@ public function getThumb()
132
134
*/
133
135
public function getNbImage ()
134
136
{
135
- $ node = $ this ->node ->filter ('.image-and-nb > .nb > .value ' );
137
+ $ node = $ this ->node ->filter ('.item_imageNumber ' );
136
138
137
139
return $ this ->getFieldValue ($ node , 0 , function ($ value ) {
138
140
return (int )trim ($ value );
@@ -144,7 +146,7 @@ public function getNbImage()
144
146
*/
145
147
public function getPlacement ()
146
148
{
147
- $ node = $ this ->node ->filter ('.placement ' );
149
+ $ node = $ this ->node ->filter ('*[itemprop=availableAtOrFrom] ' );
148
150
149
151
return $ this ->getFieldValue ($ node , '' , function ($ value ) {
150
152
return preg_replace ('/\s+/ ' , ' ' , trim ($ value ));
@@ -157,7 +159,7 @@ public function getPlacement()
157
159
*/
158
160
public function getType ()
159
161
{
160
- $ node = $ this ->node ->filter ('.detail > . category ' );
162
+ $ node = $ this ->node ->filter ('*[itemprop= category] ' );
161
163
162
164
return $ this ->getFieldValue ($ node , false , function ($ value ) {
163
165
if ('pro ' == preg_replace ('/[\s()]+/ ' , '' , $ value )) {
@@ -170,16 +172,16 @@ public function getType()
170
172
171
173
public function getAll ()
172
174
{
173
- return (object )[
174
- 'id ' => $ this ->getId (),
175
- 'title ' => $ this ->getTitle (),
176
- 'price ' => $ this ->getPrice (),
177
- 'url ' => $ this ->getUrl (),
175
+ return (object ) [
176
+ 'id ' => $ this ->getId (),
177
+ 'title ' => $ this ->getTitle (),
178
+ 'price ' => $ this ->getPrice (),
179
+ 'url ' => $ this ->getUrl (),
178
180
'created_at ' => $ this ->getCreatedAt (),
179
- 'thumb ' => $ this ->getThumb (),
180
- 'nb_image ' => $ this ->getNbImage (),
181
- 'placement ' => $ this ->getPlacement (),
182
- 'type ' => $ this ->getType (),
181
+ 'thumb ' => $ this ->getThumb (),
182
+ 'nb_image ' => $ this ->getNbImage (),
183
+ 'placement ' => $ this ->getPlacement (),
184
+ 'type ' => $ this ->getType (),
183
185
];
184
186
}
185
187
0 commit comments