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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scrapy_tw_rental_house-2.4.0.tar.gz (52.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scrapy_tw_rental_house-2.4.0-py3-none-any.whl (61.2 kB view details)

Uploaded Python 3

File details

Details for the file scrapy_tw_rental_house-2.4.0.tar.gz.

File metadata

  • Download URL: scrapy_tw_rental_house-2.4.0.tar.gz
  • Upload date:
  • Size: 52.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.10.12 Linux/6.8.0-138-generic

File hashes

Hashes for scrapy_tw_rental_house-2.4.0.tar.gz
Algorithm Hash digest
SHA256 17fc93276ac83e5e541d9c932b470c28feb52a7a30cbc7f027f6cf0dc7f0ef09
MD5 d944688921ba3479091c99974586aefb
BLAKE2b-256 b8b473bdb64544581b3520c83e56cb18bd2a0256bc2370666aedd87cecabda9b

See more details on using hashes here.

File details

Details for the file scrapy_tw_rental_house-2.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for scrapy_tw_rental_house-2.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b58e959a75547a43e9f16d3938a022c163fca598a1d63a231a8db54bfa74e4ae
MD5 3f50145074d2e92d7f086fd641b0366d
BLAKE2b-256 33818cb176fb5036b480d8c37b68bbb262fb2f085a72e0772eee17e7055f8e2a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.4.0 This release

2 files

2.3.0

2 files

2.2.4

2 files

2.2.3

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.1.8

2 files

2.1.7

2 files

2.1.6

2 files

2.1.5

2 files

2.1.4

2 files

2.1.3

2 files

2.1.2

2 files

2.1.1

2 files

2.1.0

2 files

2.0.4

2 files

2.0.3

2 files

2.0.1

2 files

2.0.0

2 files

1.5.1

2 files

1.5.0

2 files

1.4.1

2 files

1.4.0

2 files

1.3.7

2 files

1.3.6

2 files

1.3.5

2 files

1.3.4

2 files

1.3.3

2 files

1.3.2

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 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