Scrape Yad2 in Python.
Project description
Yad2 Scraper
A Python package for scraping listings from Yad2, Israel's leading classifieds platform. This package provides a simple and flexible interface to fetch data, filter results, and extract relevant information.
NOTE: Currently, the package primarily supports the vehicles category. Support for additional categories may be added in future updates.
Features
- Fetch Listings: Retrieve listings by category (e.g., vehicles, real-estate, etc.).
- Filter Results: Apply filters such as price range, year range, and sorting order.
- Dynamic URL Generation: Generate URLs for specific categories and filters.
- Type-Safe API: Uses Python type hints (
Literal,Optional, etc.) for better code clarity and safety. - Extensible: Easily extendable to support additional categories and filters.
Installation
Install the package using pip:
pip install yad2-scraper
Usage
Fetching Category Listings
To fetch any category, use the fetch_category function:
from yad2_scraper import fetch_category, Yad2Category
# Fetch real estate category (returns a generic Yad2Category object)
real_estate_category_page1 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=1)
...
real_estate_category_page2 = fetch_category("https://www.yad2.co.il/realestate/forsale", page=2)
...
Fetching Vehicle Listings
To fetch vehicle listings for a specific category, use the fetch_vehicle_category function:
from yad2_scraper import fetch_vehicle_category, OrderVehiclesBy, Field
# Fetch cars category
cars_category = fetch_vehicle_category("cars")
for car_data in cars_category.load_next_data().iterate_vehicles():
print(car_data.model(Field.ENGLISH_TEXT))
print(car_data.test_date)
print(car_data.price)
...
# Fetch motorcycles category
motorcycle_categories = fetch_vehicle_category(
"motorcycles",
price_range=(5000, 15000),
year_range=(2010, 2020),
order_by=OrderVehiclesBy.PRICE_LOWEST_TO_HIGHEST
)
for motorcycle_tag in motorcycle_categories.get_vehicle_tags():
print(motorcycle_tag.page_link)
print(motorcycle_tag.hand)
print(motorcycle_tag.price)
...
The Scraper Object
The Yad2Scraper class is the core of the package.
It handles HTTP requests, parses responses, and provides methods to fetch and filter vehicle listings.
Creating a Scraper Instance
You can create a Yad2Scraper instance manually or use the default scraper provided by the package:
from yad2_scraper import Yad2Scraper, get_default_scraper
# Create a custom scraper instance
scraper = Yad2Scraper()
# Use the default scraper
default_scraper = get_default_scraper()
Fetching Category Listings
The fetch_category method is used to fetch listings for a specific category.
It takes a URL, a Category type, and optionally query params as arguments:
from yad2_scraper import Yad2Scraper, Yad2Category, QueryFilters, OrderBy
from yad2_scraper.vehicles import (
Yad2VehiclesCategory,
VehiclesQueryFilters,
OrderVehiclesBy,
get_vehicle_category_url
)
# Fetch businesses for sale category with filters
scraper = Yad2Scraper()
url = "https://www.yad2.co.il/products/businesses-for-sale"
query_filters = QueryFilters(price_range=(10000, 250000), order_by=OrderBy.PRICE_LOWEST_TO_HIGHEST)
business_for_sale_category = scraper.fetch_category(url, Yad2Category, params=query_filters)
# Fetch watercraft (vehicle) category with filters
url = get_vehicle_category_url("watercraft")
query_filters = VehiclesQueryFilters(year_range=(2010, 2020), order_by=OrderVehiclesBy.DATE)
watercraft_category = scraper.fetch_category(url, Yad2VehiclesCategory, params=query_filters)
Attributes & Methods
The Yad2Scraper object contains a lot of additional attributes & methods which you can use.
Please check out the actual code documentation for more details.
Contributing
Contributions are welcomed! Here’s how you can get started:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Write tests for your changes.
- Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
For questions, issues, or feature requests, please open an issue on the GitHub repository.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yad2_scraper-0.5.2.tar.gz.
File metadata
- Download URL: yad2_scraper-0.5.2.tar.gz
- Upload date:
- Size: 13.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.0 CPython/3.13.2 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e58ca2ceae220dce3f9fee8eaa26a93f5e41372e61ca5def84fada75bcbfaeb
|
|
| MD5 |
d117384c6402263fa43b577c952f0944
|
|
| BLAKE2b-256 |
1469bb21fe646db4038efdf08ef4a40e1e55e913fe85b0b580279a449ccff237
|
File details
Details for the file yad2_scraper-0.5.2-py3-none-any.whl.
File metadata
- Download URL: yad2_scraper-0.5.2-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.0 CPython/3.13.2 Linux/6.8.0-1021-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
27ba9ff0ea41440de1e4aaa3a29247fdbcf678a48e62ac7a2ce42f1eab64d274
|
|
| MD5 |
70af26995d02073a3432fad8c15be0a9
|
|
| BLAKE2b-256 |
d8b71b1375ecefc44b780648ff58966128aee47bddf23a58562fd9e2134e082c
|