A Node.js bot that scrapes rental listings from Facebook groups and Marketplace using Playwright. It opens a real browser, waits for you to log in to Facebook manually, scrolls through posts, filters by price and area, and generates a web interface (resultados.html) with filterable cards to review the rentals it found.
📍 The listings are focused on the Santa Fe area of Mexico City (including nearby neighborhoods such as Memetla). You can change the target groups and search area in
config.jsandmain.js.
- Scrapes multiple Facebook groups at once (configurable).
- Scrapes Facebook Marketplace (rental search by area, e.g. "Memetla").
- Persistent session: saves your Facebook login in
./fb-session/, so you don't have to log in every time. - Automatic detection of:
- Price (
$12,000,12 mil,12000 pesos/al mes/mensuales). - Property type (Apartment, Room, House, Other).
- Area / neighborhood.
- Price (
- Smart filters: discards posts from people looking for a rental, non-housing services (chair/audio rentals, etc.), and listings over budget.
- Generates an interactive HTML interface with filters by price, group, type, and text.
- Node.js 18 or higher — download here
- Google Chrome / Chromium (Playwright installs it automatically)
- A Facebook account with access to the groups you want to scrape
- macOS, Windows, or Linux (the
open resultados.htmlcommand at the end is macOS-specific; see notes below)
Open your terminal and run these commands one by one:
git clone https://github.com/EdgarAnt/facebook-rentals-scraper.git
cd facebook-rentals-scraper
npm install
npx playwright install chromiumgit clone→ downloads the projectcd→ enters the foldernpm install→ installs the dependenciesnpx playwright install chromium→ installs the browser the bot uses
node main.jsWhen you run it:
- A visible Chrome window opens on Facebook.
- In the terminal you'll see: "Inicia sesión en Facebook y cuando estés listo presiona Enter..." (Log in to Facebook and press Enter when ready).
- Log in to Facebook inside that window (only the first time; afterwards the session is saved).
- Go back to the terminal and press Enter.
- The bot goes through each group and Marketplace, scrolling and collecting posts.
- When it finishes, it generates
resultados.htmland opens it automatically in your browser. - Press Enter again in the terminal to close the browser.
Open config.js to tune the search:
| What | How |
|---|---|
| Groups to scrape | Edit the GRUPOS list (name + URL) |
| Maximum price | Change precio_max: 50000 |
| Areas / neighborhoods | Fill in zonas: [], e.g. zonas: ["Santa Fe", "Memetla"] |
| How many posts | Raise or lower SCROLLS_POR_GRUPO: 20 |
💡 Notes:
- The first run takes longer (it downloads the browser). After that it's fast.
- The session is saved in
./fb-session/. Do not delete that folder unless you want to log in from scratch again.- The auto-open command only works on macOS. On Windows/Linux, open
resultados.htmlmanually in your browser.
All parameters live in config.js:
export const CONFIG = {
GRUPOS: [
{ nombre: "Rentas CDMX", url: "https://www.facebook.com/groups/1878242172196712/" },
{ nombre: "Rentas CDMX 2", url: "https://www.facebook.com/share/g/1EAWhbSbdV/" },
],
SCROLLS_POR_GRUPO: 20, // how many times it scrolls per group (more = more posts)
FILTROS: {
precio_max: 50000, // maximum monthly rent in MXN
zonas: [], // areas/neighborhoods to search. Empty = accept any area
},
};| Parameter | Description |
|---|---|
GRUPOS |
List of Facebook groups to scrape (nombre + url). Add as many as you want. |
SCROLLS_POR_GRUPO |
Number of scrolls per group. More scrolls = more posts, but slower. |
FILTROS.precio_max |
Maximum monthly rent (MXN). More expensive posts are flagged as "doesn't pass". |
FILTROS.zonas |
Array of neighborhoods/areas to filter (e.g. ["Roma", "Condesa"]). Empty accepts all. |
The Marketplace search is hardcoded to "Memetla" inside
main.js(functionscrapeMarketplaceMemetla). You can change the search term there for another area.
The project is simple, with two main files:
main.js— browser automation, DOM extraction, filtering, and HTML generation.config.js— theCONFIGobject with all tunable parameters.
- Persistent session —
chromium.launchPersistentContext("./fb-session")stores cookies and browser state so the login survives across runs. - Post extraction — it walks the
[role="feed"]of each group, cleans the text (removes UI buttons, photo URLs, garbled timestamps), and gets the post link while avoiding comment anchors. - Filtering (
pasaFiltros) — a post passes if:- It contains rental-offer keywords, and
- It's not from someone looking for a rental, and
- It's not a non-housing service, and
- Its price is ≤
precio_max, and - It contains an area from
zonas(if the list is non-empty).
- Marketplace — searches for items under
/marketplace/item/and adds them labeled "Marketplace Memetla". - Output — prints a summary to the terminal and generates
resultados.htmlwith an interface to filter by price, group, property type, and free text.
| Package | Use |
|---|---|
playwright |
Browser automation (Chromium). |
@anthropic-ai/sdk |
Installed for future use (not used in the current code yet). |
The project uses ESM modules ("type": "module" in package.json), so it uses import/export syntax.
facebook-rentals-scraper/
├── main.js # Main logic: scraping + filtering + HTML generation
├── config.js # Configurable parameters
├── resultados.html # Generated interface (overwritten on every run)
├── img/ # Images used in the interface (cover)
├── fb-session/ # Persistent Facebook session (DO NOT delete / DO NOT commit)
├── package.json
└── README.md
At the end, the bot runs open resultados.html to open the interface, which only works on macOS. On other systems:
- Windows: change
exec("open resultados.html")toexec("start resultados.html")inmain.js, or open the file manually. - Linux: use
exec("xdg-open resultados.html"), or open the file manually.
Either way, you can always open resultados.html manually in your browser.
This project is for personal and educational use. Scraping Facebook may go against its terms of service; use it at your own risk and in moderation.