lbc 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lbc-1.0.0/.gitignore +194 -0
- lbc-1.0.0/CHANGELOG.md +2 -0
- lbc-1.0.0/LICENSE +21 -0
- lbc-1.0.0/PKG-INFO +165 -0
- lbc-1.0.0/README.md +149 -0
- lbc-1.0.0/pyproject.toml +29 -0
- lbc-1.0.0/requirements.txt +1 -0
- lbc-1.0.0/src/lbc/__init__.py +2 -0
- lbc-1.0.0/src/lbc/client.py +85 -0
- lbc-1.0.0/src/lbc/exceptions.py +14 -0
- lbc-1.0.0/src/lbc/models/__init__.py +4 -0
- lbc-1.0.0/src/lbc/models/ad.py +32 -0
- lbc-1.0.0/src/lbc/models/attribute.py +13 -0
- lbc-1.0.0/src/lbc/models/city.py +9 -0
- lbc-1.0.0/src/lbc/models/enums.py +267 -0
- lbc-1.0.0/src/lbc/models/location.py +17 -0
- lbc-1.0.0/src/lbc/models/owner.py +9 -0
- lbc-1.0.0/src/lbc/models/proxy.py +16 -0
- lbc-1.0.0/src/lbc/models/search.py +101 -0
- lbc-1.0.0/src/lbc/session.py +39 -0
- lbc-1.0.0/src/lbc/utils.py +126 -0
- lbc-1.0.0/tests/test_search.py +33 -0
- lbc-1.0.0/utils/generate_enum_categories.py +24 -0
- lbc-1.0.0/utils/generate_enum_departments.py +21 -0
- lbc-1.0.0/utils/generate_enum_regions.py +19 -0
lbc-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py,cover
|
|
50
|
+
.hypothesis/
|
|
51
|
+
.pytest_cache/
|
|
52
|
+
cover/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
.pybuilder/
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
87
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
88
|
+
# .python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# UV
|
|
98
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
99
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
100
|
+
# commonly ignored for libraries.
|
|
101
|
+
#uv.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
|
|
116
|
+
.pdm.toml
|
|
117
|
+
.pdm-python
|
|
118
|
+
.pdm-build/
|
|
119
|
+
|
|
120
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
121
|
+
__pypackages__/
|
|
122
|
+
|
|
123
|
+
# Celery stuff
|
|
124
|
+
celerybeat-schedule
|
|
125
|
+
celerybeat.pid
|
|
126
|
+
|
|
127
|
+
# SageMath parsed files
|
|
128
|
+
*.sage.py
|
|
129
|
+
|
|
130
|
+
# Environments
|
|
131
|
+
.env
|
|
132
|
+
.venv
|
|
133
|
+
env/
|
|
134
|
+
venv/
|
|
135
|
+
ENV/
|
|
136
|
+
env.bak/
|
|
137
|
+
venv.bak/
|
|
138
|
+
|
|
139
|
+
# Spyder project settings
|
|
140
|
+
.spyderproject
|
|
141
|
+
.spyproject
|
|
142
|
+
|
|
143
|
+
# Rope project settings
|
|
144
|
+
.ropeproject
|
|
145
|
+
|
|
146
|
+
# mkdocs documentation
|
|
147
|
+
/site
|
|
148
|
+
|
|
149
|
+
# mypy
|
|
150
|
+
.mypy_cache/
|
|
151
|
+
.dmypy.json
|
|
152
|
+
dmypy.json
|
|
153
|
+
|
|
154
|
+
# Pyre type checker
|
|
155
|
+
.pyre/
|
|
156
|
+
|
|
157
|
+
# pytype static type analyzer
|
|
158
|
+
.pytype/
|
|
159
|
+
|
|
160
|
+
# Cython debug symbols
|
|
161
|
+
cython_debug/
|
|
162
|
+
|
|
163
|
+
# PyCharm
|
|
164
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
165
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
166
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
167
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
168
|
+
#.idea/
|
|
169
|
+
|
|
170
|
+
# Abstra
|
|
171
|
+
# Abstra is an AI-powered process automation framework.
|
|
172
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
173
|
+
# Learn more at https://abstra.io/docs
|
|
174
|
+
.abstra/
|
|
175
|
+
|
|
176
|
+
# Visual Studio Code
|
|
177
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
|
|
178
|
+
# that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
179
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer,
|
|
180
|
+
# you could uncomment the following to ignore the enitre vscode folder
|
|
181
|
+
# .vscode/
|
|
182
|
+
|
|
183
|
+
# Ruff stuff:
|
|
184
|
+
.ruff_cache/
|
|
185
|
+
|
|
186
|
+
# PyPI configuration file
|
|
187
|
+
.pypirc
|
|
188
|
+
|
|
189
|
+
# Cursor
|
|
190
|
+
# Cursor is an AI-powered code editor. `.cursorignore` specifies files/directories to
|
|
191
|
+
# exclude from AI features like autocomplete and code analysis. Recommended for sensitive data
|
|
192
|
+
# refer to https://docs.cursor.com/context/ignore-files
|
|
193
|
+
.cursorignore
|
|
194
|
+
.cursorindexingignore
|
lbc-1.0.0/CHANGELOG.md
ADDED
lbc-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Étienne Hodé
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
lbc-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lbc
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Unofficial client for Leboncoin API
|
|
5
|
+
Project-URL: Homepage, https://github.com/etienne-hd/lbc-py
|
|
6
|
+
Project-URL: Repository, https://github.com/etienne-hd/lbc-py
|
|
7
|
+
Project-URL: Changelog, https://github.com/etienne-hd/lbc-py/blob/main/CHANGELOG.md
|
|
8
|
+
Author-email: Etienne HODE <hode.etienne@gmail.com>
|
|
9
|
+
Maintainer-email: Etienne HODE <hode.etienne@gmail.com>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: api,lbc,leboncoin,wrapper
|
|
13
|
+
Requires-Python: >=3.9
|
|
14
|
+
Requires-Dist: curl-cffi==0.11.3
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
|
|
17
|
+
# lbc
|
|
18
|
+
[](https://pypi.org/project/lbc)
|
|
19
|
+

|
|
20
|
+
[](https://github.com/etienne-hd/lbc/blob/master/LICENSE)
|
|
21
|
+
|
|
22
|
+
**Unofficial client for Leboncoin API**
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
import lbc
|
|
26
|
+
|
|
27
|
+
client = lbc.Client()
|
|
28
|
+
|
|
29
|
+
location = lbc.City(
|
|
30
|
+
lat=48.85994982004764,
|
|
31
|
+
lng=2.33801967847424,
|
|
32
|
+
radius=10_000, # 10 km
|
|
33
|
+
city="Paris"
|
|
34
|
+
)
|
|
35
|
+
|
|
36
|
+
result = client.search(
|
|
37
|
+
text="maison",
|
|
38
|
+
locations=[location],
|
|
39
|
+
page=1,
|
|
40
|
+
limit=35,
|
|
41
|
+
sort=lbc.Sort.NEWEST,
|
|
42
|
+
ad_type=lbc.AdType.OFFER,
|
|
43
|
+
category=lbc.Category.IMMOBILIER,
|
|
44
|
+
square=[200, 400],
|
|
45
|
+
price=[300_000, 700_000]
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
for ad in result.ads:
|
|
49
|
+
print(ad.url, ad.subject, ad.price)
|
|
50
|
+
```
|
|
51
|
+
*lbc is not affiliated with, endorsed by, or in any way associated with Leboncoin or its services. Use at your own risk.*
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
Required Python 3.9+
|
|
55
|
+
```bash
|
|
56
|
+
pip install lbc
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Usage
|
|
60
|
+
### Client
|
|
61
|
+
To create client you need to use lbc.Client class
|
|
62
|
+
```python
|
|
63
|
+
import lbc
|
|
64
|
+
|
|
65
|
+
client = lbc.Client()
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
#### Proxy
|
|
69
|
+
You can also configure the client to use a proxy by providing a `Proxy` object:
|
|
70
|
+
```python
|
|
71
|
+
proxy = lbc.Proxy(
|
|
72
|
+
host=...,
|
|
73
|
+
port=...,
|
|
74
|
+
username=...,
|
|
75
|
+
password=...
|
|
76
|
+
)
|
|
77
|
+
client = lbc.Client(proxy=proxy)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
### Search
|
|
82
|
+
|
|
83
|
+
To perform a search, use the `client.search` method.
|
|
84
|
+
|
|
85
|
+
This function accepts keyword arguments (`**kwargs`) to customize your query.
|
|
86
|
+
For example, if you're looking for houses that include both land and parking, you can specify:
|
|
87
|
+
|
|
88
|
+
```python
|
|
89
|
+
real_estate_type=["3", "4"]
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
These values correspond to what you’d find in a typical Leboncoin URL, like:
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
https://www.leboncoin.fr/recherche?category=9&text=maison&...&real_estate_type=3,4
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Here's a complete example of a search query:
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
client.search(
|
|
102
|
+
text="maison",
|
|
103
|
+
locations=[location],
|
|
104
|
+
page=1,
|
|
105
|
+
limit=35,
|
|
106
|
+
limit_alu=0,
|
|
107
|
+
sort=lbc.Sort.NEWEST,
|
|
108
|
+
ad_type=lbc.AdType.OFFER,
|
|
109
|
+
category=lbc.Category.IMMOBILIER,
|
|
110
|
+
owner_type=lbc.OwnerType.ALL,
|
|
111
|
+
search_in_title_only=True,
|
|
112
|
+
square=[200, 400],
|
|
113
|
+
price=[300_000, 700_000],
|
|
114
|
+
)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Location
|
|
118
|
+
|
|
119
|
+
The `locations` parameter accepts a list of one or more location objects. You can use one of the following:
|
|
120
|
+
|
|
121
|
+
* `lbc.Region(...)`
|
|
122
|
+
* `lbc.Department(...)`
|
|
123
|
+
* `lbc.City(...)`
|
|
124
|
+
|
|
125
|
+
Each one corresponds to a different level of geographic granularity.
|
|
126
|
+
|
|
127
|
+
#### City example
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
location = lbc.City(
|
|
131
|
+
lat=48.85994982004764,
|
|
132
|
+
lng=2.33801967847424,
|
|
133
|
+
radius=10_000, # in meters
|
|
134
|
+
city="Paris"
|
|
135
|
+
)
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
#### Region / Department example
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
from lbc import Region, Department
|
|
142
|
+
|
|
143
|
+
region = Region.ILE_DE_FRANCE
|
|
144
|
+
department = Department.PARIS
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### 403 Error
|
|
148
|
+
|
|
149
|
+
If you encounter a **403 Forbidden** error, it usually means your requests are being blocked by [Datadome](https://datadome.co).
|
|
150
|
+
To resolve this:
|
|
151
|
+
|
|
152
|
+
* Try reducing the request frequency (add delays between requests).
|
|
153
|
+
* If you're using a proxy, make sure it is **clean** and preferably located in **France**.
|
|
154
|
+
|
|
155
|
+
Using residential or mobile proxies can also help avoid detection.
|
|
156
|
+
|
|
157
|
+
## License
|
|
158
|
+
|
|
159
|
+
This project is licensed under the MIT License.
|
|
160
|
+
|
|
161
|
+
## Support
|
|
162
|
+
|
|
163
|
+
<a href="https://www.buymeacoffee.com/etienneh" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
|
164
|
+
|
|
165
|
+
You can contact me via [Telegram](https://t.me/etienne_hd) or [Discord](https://discord.com/users/1153975318990827552) if you need help with scraping services or want to write a library.
|
lbc-1.0.0/README.md
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
# lbc
|
|
2
|
+
[](https://pypi.org/project/lbc)
|
|
3
|
+

|
|
4
|
+
[](https://github.com/etienne-hd/lbc/blob/master/LICENSE)
|
|
5
|
+
|
|
6
|
+
**Unofficial client for Leboncoin API**
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
import lbc
|
|
10
|
+
|
|
11
|
+
client = lbc.Client()
|
|
12
|
+
|
|
13
|
+
location = lbc.City(
|
|
14
|
+
lat=48.85994982004764,
|
|
15
|
+
lng=2.33801967847424,
|
|
16
|
+
radius=10_000, # 10 km
|
|
17
|
+
city="Paris"
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
result = client.search(
|
|
21
|
+
text="maison",
|
|
22
|
+
locations=[location],
|
|
23
|
+
page=1,
|
|
24
|
+
limit=35,
|
|
25
|
+
sort=lbc.Sort.NEWEST,
|
|
26
|
+
ad_type=lbc.AdType.OFFER,
|
|
27
|
+
category=lbc.Category.IMMOBILIER,
|
|
28
|
+
square=[200, 400],
|
|
29
|
+
price=[300_000, 700_000]
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
for ad in result.ads:
|
|
33
|
+
print(ad.url, ad.subject, ad.price)
|
|
34
|
+
```
|
|
35
|
+
*lbc is not affiliated with, endorsed by, or in any way associated with Leboncoin or its services. Use at your own risk.*
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
Required Python 3.9+
|
|
39
|
+
```bash
|
|
40
|
+
pip install lbc
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
### Client
|
|
45
|
+
To create client you need to use lbc.Client class
|
|
46
|
+
```python
|
|
47
|
+
import lbc
|
|
48
|
+
|
|
49
|
+
client = lbc.Client()
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
#### Proxy
|
|
53
|
+
You can also configure the client to use a proxy by providing a `Proxy` object:
|
|
54
|
+
```python
|
|
55
|
+
proxy = lbc.Proxy(
|
|
56
|
+
host=...,
|
|
57
|
+
port=...,
|
|
58
|
+
username=...,
|
|
59
|
+
password=...
|
|
60
|
+
)
|
|
61
|
+
client = lbc.Client(proxy=proxy)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
### Search
|
|
66
|
+
|
|
67
|
+
To perform a search, use the `client.search` method.
|
|
68
|
+
|
|
69
|
+
This function accepts keyword arguments (`**kwargs`) to customize your query.
|
|
70
|
+
For example, if you're looking for houses that include both land and parking, you can specify:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
real_estate_type=["3", "4"]
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
These values correspond to what you’d find in a typical Leboncoin URL, like:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
https://www.leboncoin.fr/recherche?category=9&text=maison&...&real_estate_type=3,4
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Here's a complete example of a search query:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
client.search(
|
|
86
|
+
text="maison",
|
|
87
|
+
locations=[location],
|
|
88
|
+
page=1,
|
|
89
|
+
limit=35,
|
|
90
|
+
limit_alu=0,
|
|
91
|
+
sort=lbc.Sort.NEWEST,
|
|
92
|
+
ad_type=lbc.AdType.OFFER,
|
|
93
|
+
category=lbc.Category.IMMOBILIER,
|
|
94
|
+
owner_type=lbc.OwnerType.ALL,
|
|
95
|
+
search_in_title_only=True,
|
|
96
|
+
square=[200, 400],
|
|
97
|
+
price=[300_000, 700_000],
|
|
98
|
+
)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Location
|
|
102
|
+
|
|
103
|
+
The `locations` parameter accepts a list of one or more location objects. You can use one of the following:
|
|
104
|
+
|
|
105
|
+
* `lbc.Region(...)`
|
|
106
|
+
* `lbc.Department(...)`
|
|
107
|
+
* `lbc.City(...)`
|
|
108
|
+
|
|
109
|
+
Each one corresponds to a different level of geographic granularity.
|
|
110
|
+
|
|
111
|
+
#### City example
|
|
112
|
+
|
|
113
|
+
```python
|
|
114
|
+
location = lbc.City(
|
|
115
|
+
lat=48.85994982004764,
|
|
116
|
+
lng=2.33801967847424,
|
|
117
|
+
radius=10_000, # in meters
|
|
118
|
+
city="Paris"
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### Region / Department example
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from lbc import Region, Department
|
|
126
|
+
|
|
127
|
+
region = Region.ILE_DE_FRANCE
|
|
128
|
+
department = Department.PARIS
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### 403 Error
|
|
132
|
+
|
|
133
|
+
If you encounter a **403 Forbidden** error, it usually means your requests are being blocked by [Datadome](https://datadome.co).
|
|
134
|
+
To resolve this:
|
|
135
|
+
|
|
136
|
+
* Try reducing the request frequency (add delays between requests).
|
|
137
|
+
* If you're using a proxy, make sure it is **clean** and preferably located in **France**.
|
|
138
|
+
|
|
139
|
+
Using residential or mobile proxies can also help avoid detection.
|
|
140
|
+
|
|
141
|
+
## License
|
|
142
|
+
|
|
143
|
+
This project is licensed under the MIT License.
|
|
144
|
+
|
|
145
|
+
## Support
|
|
146
|
+
|
|
147
|
+
<a href="https://www.buymeacoffee.com/etienneh" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
|
|
148
|
+
|
|
149
|
+
You can contact me via [Telegram](https://t.me/etienne_hd) or [Discord](https://discord.com/users/1153975318990827552) if you need help with scraping services or want to write a library.
|
lbc-1.0.0/pyproject.toml
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lbc"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Unofficial client for Leboncoin API"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = {text = "MIT"}
|
|
7
|
+
requires-python = ">=3.9"
|
|
8
|
+
|
|
9
|
+
authors = [
|
|
10
|
+
{name = "Etienne HODE", email = "hode.etienne@gmail.com"}
|
|
11
|
+
]
|
|
12
|
+
maintainers = [
|
|
13
|
+
{name = "Etienne HODE", email = "hode.etienne@gmail.com"}
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
dependencies = [
|
|
17
|
+
"curl_cffi==0.11.3"
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
keywords = ["lbc", "leboncoin", "wrapper", "api"]
|
|
21
|
+
|
|
22
|
+
[project.urls]
|
|
23
|
+
Homepage = "https://github.com/etienne-hd/lbc-py"
|
|
24
|
+
Repository = "https://github.com/etienne-hd/lbc-py"
|
|
25
|
+
Changelog = "https://github.com/etienne-hd/lbc-py/blob/main/CHANGELOG.md"
|
|
26
|
+
|
|
27
|
+
[build-system]
|
|
28
|
+
requires = ["hatchling"]
|
|
29
|
+
build-backend = "hatchling.build"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
curl_cffi==0.11.3
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
from .session import Session
|
|
2
|
+
from .models import Proxy, Search, Category, AdType, OwnerType, Sort, Region, Department, City
|
|
3
|
+
from .exceptions import DatadomeError, RequestError
|
|
4
|
+
from .utils import build_search_payload_with_args
|
|
5
|
+
|
|
6
|
+
from typing import Optional, List, Union
|
|
7
|
+
|
|
8
|
+
class Client(Session):
|
|
9
|
+
def __init__(self, proxy: Optional[Proxy] = None):
|
|
10
|
+
super().__init__(proxy=proxy)
|
|
11
|
+
|
|
12
|
+
def _fetch(self, method: str, url: str, payload: Optional[dict] = None, timeout: int = 30) -> dict:
|
|
13
|
+
"""
|
|
14
|
+
Internal method to send an HTTP request using the configured session.
|
|
15
|
+
|
|
16
|
+
Args:
|
|
17
|
+
method (staticmethod): HTTP method to use (e.g., `GET`, `POST`).
|
|
18
|
+
url (str): Full URL of the API endpoint.
|
|
19
|
+
payload (Optional[dict], optional): JSON payload to send with the request. Used for POST/PUT methods. Defaults to None.
|
|
20
|
+
timeout (int, optional): Timeout for the request, in seconds. Defaults to 30.
|
|
21
|
+
|
|
22
|
+
Raises:
|
|
23
|
+
DatadomeError: Raised when the request is blocked by Datadome protection (HTTP 403).
|
|
24
|
+
RequestError: Raised for any other non-successful HTTP response.
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
dict: Parsed JSON response from the server.
|
|
28
|
+
"""
|
|
29
|
+
response = self.session.request(
|
|
30
|
+
method=method,
|
|
31
|
+
url=url,
|
|
32
|
+
json=payload,
|
|
33
|
+
timeout=timeout
|
|
34
|
+
)
|
|
35
|
+
if response.ok:
|
|
36
|
+
return response.json()
|
|
37
|
+
elif response.status_code == 403:
|
|
38
|
+
if self.proxy:
|
|
39
|
+
raise DatadomeError(f"Access blocked by Datadome: your proxy appears to have a poor reputation, try to change it.")
|
|
40
|
+
else:
|
|
41
|
+
raise DatadomeError(f"Access blocked by Datadome: your activity was flagged as suspicious. Please avoid sending excessive requests.")
|
|
42
|
+
else:
|
|
43
|
+
raise RequestError(f"Request failed with status code {response.status_code}.")
|
|
44
|
+
|
|
45
|
+
def search(
|
|
46
|
+
self,
|
|
47
|
+
text: Optional[str] = None,
|
|
48
|
+
category: Category = Category.TOUTES_CATEGORIES,
|
|
49
|
+
sort: Sort = Sort.RELEVANCE,
|
|
50
|
+
locations: Optional[Union[List[Union[Region, Department, City]], Union[Region, Department, City]]] = None,
|
|
51
|
+
limit: int = 35,
|
|
52
|
+
limit_alu: int = 3,
|
|
53
|
+
page: int = 1,
|
|
54
|
+
ad_type: AdType = AdType.OFFER,
|
|
55
|
+
owner_type: Optional[OwnerType] = None,
|
|
56
|
+
search_in_title_only: bool = False,
|
|
57
|
+
**kwargs
|
|
58
|
+
) -> Search:
|
|
59
|
+
"""
|
|
60
|
+
Perform a classified ads search on Leboncoin with the specified criteria.
|
|
61
|
+
|
|
62
|
+
Args:
|
|
63
|
+
text (Optional[str], optional): Search keywords. If None, returns all matching ads without filtering by keyword. Defaults to None.
|
|
64
|
+
category (Category, optional): Category to search in. Defaults to Category.TOUTES_CATEGORIES.
|
|
65
|
+
sort (Sort, optional): Sorting method for results (e.g., relevance, date, price). Defaults to Sort.RELEVANCE.
|
|
66
|
+
locations (Optional[Union[List[Union[Region, Department, City]], Union[Region, Department, City]]], optional): One or multiple locations (region, department, or city) to filter results. Defaults to None.
|
|
67
|
+
limit (int, optional): Maximum number of results to return. Defaults to 35.
|
|
68
|
+
limit_alu (int, optional): Number of ALU (Annonces Lu / similar ads) suggestions to include. Defaults to 3.
|
|
69
|
+
page (int, optional): Page number to retrieve for paginated results. Defaults to 1.
|
|
70
|
+
ad_type (AdType, optional): Type of ad (offer or request). Defaults to AdType.OFFER.
|
|
71
|
+
owner_type (Optional[OwnerType], optional): Filter by seller type (individual, professional, or all). Defaults to None.
|
|
72
|
+
search_in_title_only (bool, optional): If True, search will only be performed on ad titles. Defaults to False.
|
|
73
|
+
**kwargs: Additional advanced filters such as price range (`price=(min, max)`), surface area (`square=(min, max)`), property type, and more.
|
|
74
|
+
|
|
75
|
+
Returns:
|
|
76
|
+
Search: A `Search` object containing the parsed search results.
|
|
77
|
+
"""
|
|
78
|
+
payload = build_search_payload_with_args(
|
|
79
|
+
text=text, category=category, sort=sort, locations=locations,
|
|
80
|
+
limit=limit, limit_alu=limit_alu, page=page, ad_type=ad_type,
|
|
81
|
+
owner_type=owner_type, search_in_title_only=search_in_title_only, **kwargs
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
body = self._fetch(method="POST", url="https://api.leboncoin.fr/finder/search", payload=payload)
|
|
85
|
+
return Search.build(raw=body)
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
class LBCError(Exception):
|
|
2
|
+
"""Base exception for all errors raised by the LBC client."""
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class InvalidValue(LBCError):
|
|
6
|
+
"""Raised when a provided value is invalid or improperly formatted."""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RequestError(LBCError):
|
|
10
|
+
"""Raised when an HTTP request fails with a non-success status code."""
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class DatadomeError(RequestError):
|
|
14
|
+
"""Raised when access is blocked by Datadome anti-bot protection."""
|