Bouss /
boussimmo
| 1 | <?php |
||
| 2 | |||
| 3 | namespace App\Parser; |
||
| 4 | |||
| 5 | use App\Enum\Provider; |
||
| 6 | use App\Exception\ParseException; |
||
| 7 | use Exception; |
||
| 8 | use Symfony\Component\DomCrawler\Crawler; |
||
| 9 | |||
| 10 | class LeBonCoinParser extends AbstractParser |
||
| 11 | { |
||
| 12 | protected const PROVIDER = Provider::LEBONCOIN; |
||
| 13 | |||
| 14 | protected const SELECTOR_AD_WRAPPER = 'table[style*="border: solid 1px #e6ebef"]'; |
||
| 15 | protected const SELECTOR_TITLE = 'td:nth-child(2) > a > span:first-of-type'; |
||
| 16 | protected const SELECTOR_LOCATION = 'td:nth-child(2) > a > div > span'; |
||
| 17 | protected const SELECTOR_PHOTO = 'td:nth-child(1) div'; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * {@inheritDoc} |
||
| 21 | */ |
||
| 22 | 1 | protected function parsePhoto(Crawler $crawler): ?string |
|
| 23 | { |
||
| 24 | try { |
||
| 25 | 1 | $backgroundImage = $crawler->filter(static::SELECTOR_PHOTO)->attr('style'); |
|
| 26 | |||
| 27 | 1 | if (1 === preg_match('/background-image: url\((.*)\)/', $backgroundImage, $matches)) { |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 28 | 1 | return $matches[1]; |
|
| 29 | } |
||
| 30 | |||
| 31 | throw new ParseException('Error while parsing the photo: no property "background-image" found'); |
||
| 32 | } catch (Exception $e) { |
||
| 33 | throw new ParseException('Error while parsing the photo: ' . $e->getMessage()); |
||
| 34 | } |
||
| 35 | } |
||
| 36 | } |
||
| 37 |