Script for scraping Taiwan CPC (中油) official direct-operated gas station information from vipmbr.cpc.com.tw Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2.0 KiB
2.0 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Overview
This skill contains a single standalone script for scraping Taiwan CPC (中油) official direct-operated gas station information. The script fetches data from https://vipmbr.cpc.com.tw/mbwebs/service_search.aspx using form POST requests and parses the HTML response.
Architecture
The script uses only Python stdlib (no external dependencies):
HTMLParser- CustomStationTableParserclass extracts data from the#MyGridView1tableurllib- Handles HTTP requests with proper User-Agent and form data encoding__VIEWSTATE/__EVENTVALIDATION- ASP.NET hidden fields are extracted and submitted in POST requests
The query flow:
- GET initial page to extract ASP.NET hidden fields
- POST with
TypeGroup=rbGroup2to select "direct-operated stations" (直營站) - Extract hidden fields again
- POST with
btnQuery=查詢to submit the query - Parse HTML response table
Common Commands
Get all direct-operated stations (default text output)
python3 skills/c/cpc_direct_stations.py
Query by city
python3 skills/c/cpc_direct_stations.py --city 台北市
Filter by keyword (station name or address)
python3 skills/c/cpc_direct_stations.py --city 新北市 --keyword 中山
Export as JSON
python3 skills/c/cpc_direct_stations.py --city 台北市 --format json
Export as CSV (with BOM for Excel compatibility)
python3 skills/c/cpc_direct_stations.py --format csv --out cpc_stations.csv
City Codes
The CITY_MAP dict maps Chinese city names to CPC internal codes (e.g., "台北市": "A "). Supported cities include all Taiwan counties and cities.
Output Schema
Each station record contains:
縣市- County/City鄉鎮區- District類別- Category (e.g., "直營站")站名- Station name站代號- Station code地址- Address電話- Phone number營業時間- Business hours