A Python web scraper for extracting real estate listings from Mubawab.ma, Morocco's leading property website. This tool allows you to collect property data from multiple cities and analyze market trends.
- Multi-language Support: Scrape in French or English
- Multi-city Coverage: Support for 5 major Moroccan cities
- Comprehensive Data Extraction: Price, location, area, rooms, bedrooms, bathrooms
- Automatic Pagination: Scrapes multiple pages until no new listings are found
- Data Export: Saves results to JSON files
- Market Analysis: Calculates average prices and price per square meter
- Robust Error Handling: Handles network errors and missing data gracefully
- Rabat
- Tanger (Tangier)
- Marrakech
- Casablanca
- Agadir
pip install beautifulsoup4 requests
- Clone or download the script
- Install required dependencies:
pip install beautifulsoup4 requests
- Run the script:
python Scraper - Mubawab.py
- Select Language: Choose between French (1) or English (2)
- Select City: Pick from the 5 available cities
- Wait for Scraping: The script will automatically scrape all available pages
- View Results: See scraped data in terminal and exported JSON file
--------Mubawab Scraper--------
Languages:
1- French
2- English
> 1
-------------------------------------------------
1- Rabat
2- Tanger
3- Marrakech
4- Casablanca
5- Agadir
Choisissez la ville: 1
Scraping Rabat listings...
The scraper provides two types of output:
- Real-time scraping progress
- Individual listing details
- Summary statistics by location
- Average prices and price per m²
- Structured data saved as
data_{city}.json
- Organized by location and property title
- Complete property details for further analysis
{
"Rabat Centre": {
"Appartement 3 chambres": {
"price": 2500000,
"area": 120,
"rooms": 4,
"bedrooms": 3,
"bathrooms": 2
}
}
}
Field | Description |
---|---|
price |
Property price in Moroccan Dirhams (DH) |
area |
Property area in square meters (m²) |
rooms |
Total number of rooms |
bedrooms |
Number of bedrooms |
bathrooms |
Number of bathrooms |
- Respectful Scraping: Includes random delays (1-3 seconds) between requests
- Multiple Selectors: Uses fallback CSS selectors for robust data extraction
- User-Agent Rotation: Mimics real browser requests
- Error Handling: Graceful handling of network timeouts and parsing errors
- Random delays between requests to avoid overwhelming the server
- Timeout handling for network requests
- Respectful scraping practices
- Website Dependency: Functionality depends on Mubawab.ma's HTML structure
- Rate Limiting: May need to adjust delays for heavy usage
- Geographic Scope: Limited to 5 major Moroccan cities
- Data Completeness: Some listings may have incomplete information
- Personal Use: Intended for personal research and analysis
- Data Usage: Respect the website's terms of service
- Rate Limits: Don't overload the server with requests
-
No Data Scraped
- Check internet connection
- Website structure may have changed
- Try different city/language combination
-
Request Timeouts
- Increase timeout value in requests.get()
- Check network stability
-
Parsing Errors
- Website HTML structure may have changed
- Update CSS selectors if needed
⚠️ No containers found
: No listings found on the page⚠️ Incomplete listing found
: Some required fields are missingRequest failed
: Network connection issue
Feel free to submit issues, feature requests, or pull requests to improve the scraper's functionality.
This tool is for educational and research purposes. Users are responsible for complying with Mubawab.ma's terms of service and applicable laws. The authors are not responsible for any misuse of this tool.
This project is open source. Please use responsibly and ethically.