Skip to content

Commit 5b92fbb

Browse files
committed
feat: add scraper for senate data
1 parent 5434a48 commit 5b92fbb

12 files changed

Lines changed: 16475 additions & 0 deletions

senate/README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Philippine Senate Bill Scraper
2+
3+
Python scraper for Philippine Senate bills from https://web.senate.gov.ph
4+
5+
## Main Scraper: `main.py`
6+
7+
A comprehensive scraper that:
8+
- **Metadata Extraction**: Extracts senators, committees, and legislative statuses for Neo4j mapping
9+
- **Discovery Phase**: Uses Selenium to navigate pages and discover all bill numbers
10+
- **Fetching Phase**: Uses fast async HTTP requests to download bill details with "All Information" view
11+
12+
## Installation
13+
14+
```bash
15+
# Create virtual environment
16+
python3 -m venv venv
17+
source venv/bin/activate
18+
19+
# Install dependencies
20+
pip install -r requirements.txt
21+
```
22+
23+
## Usage
24+
25+
### Extract metadata for Neo4j mapping
26+
```bash
27+
# Extract metadata for all congresses (13-20)
28+
python main.py --metadata
29+
30+
# Or specify specific congresses
31+
python main.py --metadata --congress 19 20
32+
```
33+
34+
### Discover all bill numbers
35+
```bash
36+
python main.py --discover --congress 19 --type ALL
37+
```
38+
39+
### Fetch bill details
40+
```bash
41+
python main.py --fetch --congress 19 --type ALL --workers 30
42+
```
43+
44+
### Complete workflow (all steps)
45+
```bash
46+
python main.py --metadata --discover --fetch --congress 19 --workers 30
47+
```
48+
49+
### Additional options
50+
```bash
51+
# Force rediscovery (ignore cache)
52+
python main.py --discover --congress 19 --type HBN --force
53+
54+
# Show browser during discovery
55+
python main.py --discover --congress 19 --show-browser
56+
```
57+
58+
## Options
59+
60+
- `--metadata`: Extract metadata (senators, committees, statuses)
61+
- `--discover`: Run discovery phase to get bill numbers
62+
- `--fetch`: Run fetching phase to download bill details
63+
- `--congress`: Congress number(s) (e.g., 19, 20)
64+
- `--type`: Bill type (SBN, HBN, or ALL)
65+
- `--workers`: Number of concurrent workers for fetching (default: 20)
66+
- `--dir`: Output directory for bills
67+
- `--metadata-dir`: Directory for metadata and cache files (default: metadata)
68+
- `--force`: Force rediscovery even if cache exists
69+
- `--show-browser`: Show browser window during discovery
70+
71+
## Output Structure
72+
73+
### Metadata Directory (`metadata/`)
74+
75+
#### Congress Metadata Files
76+
- `congress_13.json` - Metadata for Congress 13 (senators, committees, statuses)
77+
- `congress_14.json` - Metadata for Congress 14
78+
- `congress_15.json` - Metadata for Congress 15
79+
- `congress_16.json` - Metadata for Congress 16
80+
- `congress_17.json` - Metadata for Congress 17
81+
- `congress_18.json` - Metadata for Congress 18
82+
- `congress_19.json` - Metadata for Congress 19
83+
- `congress_20.json` - Metadata for Congress 20
84+
- `all_congresses.json` - Combined metadata for all congresses
85+
86+
#### Bill Discovery Cache Files
87+
- `bills_congress_19_SBN.json` - Cached SBN bill numbers for Congress 19
88+
- `bills_congress_19_HBN.json` - Cached HBN bill numbers for Congress 19
89+
- `bills_congress_XX_[SBN|HBN].json` - Cached bill numbers for other congresses
90+
91+
### Bill Output (`congress/19/`)
92+
```
93+
congress/
94+
└── 19/
95+
├── SBN/
96+
│ ├── index.yml
97+
│ ├── SBN-00001.toml
98+
│ ├── SBN-00002.toml
99+
│ └── ...
100+
└── HBN/
101+
├── index.yml
102+
├── HBN-00001.toml
103+
├── HBN-00004.toml
104+
├── HBN-00005.toml
105+
├── HBN-00014.toml
106+
└── ...
107+
```
108+
109+
## Known Issues
110+
111+
- **HBN Bill Gaps**: HBN bills have non-consecutive numbering with massive gaps. For Congress 19, bills include: 1, 4, 5, 14, 24, 102, 198, 425, 1028... up to 11545
112+
- **ASP.NET Forms**: The website uses ASP.NET postback forms for dropdown changes, which is why Selenium is used for discovery
113+
- **Rate Limiting**: Be respectful and don't overwhelm the server. The scraper includes built-in delays
114+
115+
## Workflow for Neo4j Import
116+
117+
1. **Extract metadata** to get congress-specific reference data for senators, committees, and statuses (defaults to congresses 13-20)
118+
2. **Discover bills** to get all bill numbers (handles non-consecutive HBN bills)
119+
3. **Fetch details** with multiple workers for fast parallel processing
120+
4. **Import to Neo4j** using the structured TOML files with proper codes for relationships

0 commit comments

Comments
 (0)