rfussien/leboncoin-crawler

此包已废弃,不再维护。没有建议的替代包。

使从leboncoin.fr提取数据变得容易

安装: 358

依赖项: 0

建议者: 0

安全: 0

星标: 35

关注者: 3

分叉: 16

语言:HTML

2.3.0 2017-05-12 13:18 UTC

This package is auto-updated.

Last update: 2022-02-01 12:43:28 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

这是一个用于leboncoin.fr网站的小型爬虫包。

为什么?

leboncoin.fr是法国最著名的分类广告网站之一。无论你在寻找什么,可能都在那里。它拥有大量的广告,且使用非常快速简单。

然而,第一个问题是当你需要以网站无法帮助你的方式利用搜索结果时。实际上,搜索结果页面的数据非常有限。例如,当我在寻找汽车时,如果能得到里程数会很好;当我在寻找公寓时,如果能得到面积会更好。

第二个问题是,在当前网站上保存搜索非常痛苦。你想要保存的所有搜索都只给出一个结果页面。这很愚蠢,但无论如何。

最后一个问题也是第三个问题,你被迫使用某些标准选择值。例如,当我寻找摩托车时,我在寻找那些发动机排量大于1200cc的摩托车。事实上,输入中可用的最大值是1000cc,因为有很多1000cc的摩托车广告,这使得搜索变得更加复杂。我确实发了一封邮件要求增加一个额外的值,但我没有得到任何回复(我本来也不期望得到回复)。因此,我不得不在每次请求时都更改查询字符串中的值...真是浪费时间...

因此,出于所有这些小小的原因,我决定编写我的旧式网络爬虫,以便能够从网站上提取数据到任何地方(数据库、数组、json、api,等等)。

要求

  • PHP 7
  • [可选] PHPUnit 以执行测试套件

安装

$ composer require rfussien/leboncoin-crawler

使用

超级简单!!

从搜索结果页面获取结构化数据

(new Lbc\GetFrom)->search('<search_result_url>');
// or with detailed ads
(new Lbc\GetFrom)->search('<search_result_url>', true);

输出示例:

[
  'page' => 2,
  'links' => [
    'current' => 'https://www.leboncoin.fr/ventes_immobilieres/offres/basse_normandie/?o=2&sqs=12&ret=1&location=Caen%2014000',
    'previous' => 'https://www.leboncoin.fr/ventes_immobilieres/offres/basse_normandie/?o=1&sqs=12&ret=1&location=Caen%2014000',
    'next' => 'https://www.leboncoin.fr/ventes_immobilieres/offres/basse_normandie/?o=3&sqs=12&ret=1&location=Caen%2014000',
  ],
  'total_ads' => 466,
  'total_page' => 14,
  'ads_per_page' => 35,
  'category' => 'ventes_immobilieres',
  'location' => 'Caen 14000',
  'search_area' => 'basse_normandie',
  'sort_by' => 'date',
  'type' => 'all',
  'ads' => [
    1117890265 => [
      'id' => '1117890265',
      'titre' => 'Maison 7 pièces 243 m²',
      'is_pro' => true,
      'prix' => 490000,
      'url' => 'https://www.leboncoin.fr/ventes_immobilieres/1117890265.htm',
      'created_at' => '2017-04-06',
      'images_thumbs' => 'https://img1.leboncoin.fr/ad-thumb/fdf29ab66506b52f5768c509cbd4c9940035b220.jpg',
      'nb_image' => '10',
      'placement' => 'Caen / Calvados',
    ],
    [...],
    1116940130 => [
      'id' => '1116940130',
      'titre' => 'Maison de ville 5 pièces 121 m²',
      'is_pro' => true,
      'prix' => 338000,
      'url' => 'https://www.leboncoin.fr/ventes_immobilieres/1116940130.htm',
      'created_at' => '2017-04-04',
      'images_thumbs' => 'https://img2.leboncoin.fr/ad-thumb/2bb09136b010d9009f0d5542c8699ede3f6bedfd.jpg',
      'nb_image' => '4',
      'placement' => 'Caen / Calvados',
    ],
  ],
]

从广告中获取结构化数据

(new Lbc\GetFrom)->ad('<ad_url>');
// or
(new Lbc\GetFrom)->ad('<ad_id>', '<ad_category>');

输出示例:

[
    'id'            => '1072097995',
    'category'      => 'ventes_immobilieres',
    'images_thumbs' => [
        0 => 'https://img0.leboncoin.fr/ad-thumb/6c3962c95d1be2367d8b30f8cc1c04317be61cae.jpg',
        1 => 'https://img5.leboncoin.fr/ad-thumb/9346546557dc1cf9eafc0249c8f80e27530ec36f.jpg',
        2 => 'https://img6.leboncoin.fr/ad-thumb/f0e61ab47f008ae101c0ed03e3023d34ee37df5f.jpg',
        3 => 'https://img4.leboncoin.fr/ad-thumb/60a4a187064407bc792b421189e66f87e1a2425c.jpg',
        4 => 'https://img5.leboncoin.fr/ad-thumb/d34a4ef9545e60ae88169acbe4858608ba01e8a9.jpg',
    ],
    'images'        => [
        0 => 'https://img0.leboncoin.fr/ad-image/6c3962c95d1be2367d8b30f8cc1c04317be61cae.jpg',
        1 => 'https://img5.leboncoin.fr/ad-image/9346546557dc1cf9eafc0249c8f80e27530ec36f.jpg',
        2 => 'https://img6.leboncoin.fr/ad-large/f0e61ab47f008ae101c0ed03e3023d34ee37df5f.jpg',
        3 => 'https://img4.leboncoin.fr/ad-image/60a4a187064407bc792b421189e66f87e1a2425c.jpg',
        4 => 'https://img5.leboncoin.fr/ad-image/d34a4ef9545e60ae88169acbe4858608ba01e8a9.jpg',
    ],
    'properties'    => [
        'titre'          => 'Maison 11 pièces 450 m²',
        'created_at'     => '2017-02-18',
        'is_pro'         => 1,
        'prix'           => 1185000,
        'ville'          => 'Bayeux',
        'cp'             => '14400',
        'type_de_bien'   => 'Maison',
        'pieces'         => 11,
        'surface'        => 450,
        'reference'      => '394348',
        'ges'            => 'C (de 11 à 20)',
        'classe_energie' => 'C (de 91 à 150)',
    ],
    'description'   => 'Vente Maison/villa 11 piècesI@D France - [...]3562178Référence annonce : 394348',
]

如果你深入研究源代码,会发现有很多功能。

测试

$ composer test

贡献

请参阅CONTRIBUTINGCONDUCT以获取详细信息。

安全

如果您发现任何与安全相关的问题,请通过电子邮件(remi.fussien@gmail.com)联系我,而不是使用问题跟踪器。

鸣谢

许可证

MIT许可证(MIT)。更多信息请参阅许可证文件