Skip to main content

TW Rental House Utility for Scrapy

This package is built for crawling Taiwanese rental house related website using Scrapy. As behavior of crawlers may differ from their goal, scale, and pipeline, this package provides only minimum feature set, which allow developer to list and decode a rental house web page into structured data, without knowing too much about detail HTML and API structure of each website. In addition, this package is also designed for extensibility, which allow developers to insert customized callback, manipulate data, and integrate with existing crawler structure.

Although this package provide the ability to crawl rental house website, it's developer's responsibility to ensure crawling mechanism and usage of data. Please be friendly to target website, such as consider using DOWNLOAD_DELAY or AUTO_THROTTLING to prevent bulk requesting.

Requirement

  1. Python 3.10+

Installation

poetry add scrapy-tw-rental-house

No browser needed. 591 renders both its list and its detail pages on the server, so every page is downloaded by plain HTTP.

591 specific

591 replies 403 to the default scrapy user agent, while it serves requests carrying no user agent at all just fine, so this package sets USER_AGENT to None unless the project configures its own.

Tests

Tests run against HTML saved under tests/fixtures, so they neither hit 591 nor need network access. Sockets are blocked while they run, so a test which crawls by accident fails instead of reaching 591.

poetry install --with dev
poetry run pytest

CLI

The package ships a twrh command for manual testing and monitoring — plain HTTP, no database, no Scrapy project needed:

twrh parse <saved-detail.html>   # offline: run the parser on a saved page
twrh detail <house-id>           # fetch + parse one detail page
twrh list 金門縣                  # fetch + parse one list page
twrh survey 花蓮縣                # full city sweep → completeness report
twrh harvest 花蓮縣               # stratified fixture harvest + manifest
twrh probe 花蓮縣                 # ratio assertions + exit code, for nightly checks

probe asserts on ratios over freshly discovered listings (list volume, detail success rate, parse rate, key-field fill rates) and can compare fill rates against a saved survey report via --baseline to catch silent selector drift. City names follow tw_regions.json; most subcommands also accept a raw URL or house id.

Basic Usage

This package currently support 591. Each rental house website is a Scrapy Spider class. You can either crawl entire website using default setting , which will take couple days, or customize the behaviour base on your need.

Note: The 591 list spider retrieves houses sorted by post date (newest first), instead of using 591's default ordering. This ensures consistent crawling behavior and helps track newly posted listings.

The most basic usage would be creating a new Spider class that inherit Rental591Spider:

from scrapy_twrh.spiders.rental591 import Rental591Spider

class MyAwesomeSpider(Rental591Spider):
    name='awesome'

And than start crawling by

scrapy crawl awesome

Please see example for detail usage.

Deal events (成交)

Since 591's 2026 redesign a rented listing's detail page returns 404, and the deal signal lives only in the "已成交" list (list?shType=clinch, newest deal first). Rental591Spider walks that list per city and yields one GenericHouseItem per deal with deal_status=DEAL, deal_time (the deal date, derived from 591's relative "N天前" against a base date) and n_day_deal (591's own "N天成交", days from posting to deal):

scrapy crawl awesome -a deals_only=True -a deal_lookback_days=2
twrh deals 台北市 --lookback 2           # same thing, no project needed

deal_lookback_days bounds how far back the walk goes (a daily run needs 2: today, yesterday and one day of overlap — events are idempotent). Pass deal_base_date=YYYY-MM-DD when the crawl date is pinned by the caller; the spider otherwise uses today. Houses never seen before may appear — how to store them is the caller's decision.

Items

All spiders populates 2 type of Scrapy items: GenericHouseItem and RawHouseItem.

GenericHouseItem contains normalized data field, spirders from different website will decode their data and fit into this schema in best effort.

RawHouseItem contains unnormalized data field, which keep original and structured data in best effort.

Note that both item are super set of schema. It developer's responsibility to check which field is provided when receiving an item. For example, in Rental591Spider, for a single rental house, Scrapy will get:

  1. 1x RawHouseItem + 1x GenericHouseItem during listing all houses, which provide only minimun data field for GenericHouseItem
  2. 1x RawHouseItem + 1x GenericHouseItem during retrieving house detail.

Handlers

All spiders in this package provide the following handlers:

  1. start_list, similiar to start_requests in Scrapy, control how crawler issue search/list request to find all rental houses.
  2. parse_list, similiar to parse in Scrapy, control how crawler handles response from start_list and generate request for detail house info page.
  3. parse_detail, control how crawler parse detail page.

All spiders implements their own default handler, say, default_start_list, default_parse_list, and default_parse_detail, and can be overwrite during __init__. Please see example for how to control spider behavior using handlers.

Release files for scrapy-tw-rental-house 2.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrapy-tw-rental-house 2.5.0
File Size Uploaded
scrapy_tw_rental_house-2.5.0.tar.gz 53.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scrapy-tw-rental-house 2.5.0
File Interpreter ABI Platform
scrapy_tw_rental_house-2.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 114.6 kB

Release files / scrapy_tw_rental_house-2.5.0.tar.gz

Download URL scrapy_tw_rental_house-2.5.0.tar.gz
Size 53.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4920f570f9957a8cd63da2f25a18ca16962b0bd35d736e4653474915d30e0f13
BLAKE2b-256 checksum
How to use checksums
6aed63ceb303b78933ac7f4aaeed7758d6f5daae1aaa72628e9b0fd0e1950a79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.8.0-138-generic

Release files / scrapy_tw_rental_house-2.5.0-py3-none-any.whl

Download URL scrapy_tw_rental_house-2.5.0-py3-none-any.whl
Size 61.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
10033cd57254353963665006abe05bbf2ae753e7ef45fa95fb19b1d8ef950511
BLAKE2b-256 checksum
How to use checksums
eefa860a0a54c45f88542083dbfa30b8da81b214758f140cf2bf8ae95535ec43
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.8.0-138-generic

Release history Release notifications | RSS feed

This release

2.5.0 This release

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.4

2 release files

2.2.3

2 release files

2.2.2

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.8

2 release files

2.1.7

2 release files

2.1.6

2 release files

2.1.5

2 release files

2.1.4

2 release files

2.1.3

2 release files

2.1.2

2 release files

2.1.1

2 release files

2.1.0

2 release files

2.0.4

2 release files

2.0.3

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.7

2 release files

1.3.6

2 release files

1.3.5

2 release files

1.3.4

2 release files

1.3.3

2 release files

1.3.2

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page