Files
hbr-crawler/問題排除說明.md
DonaldFang 方士碩 f524713cb6 Initial commit: HBR 文章爬蟲專案
- Scrapy 爬蟲框架,爬取 HBR 繁體中文文章
- Flask Web 應用程式,提供文章查詢介面
- SQL Server 資料庫整合
- 自動化排程與郵件通知功能

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-03 17:19:56 +08:00

111 lines
2.4 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 問題排除說明
## 當前問題
### 1. 資料庫權限問題
**錯誤訊息**
```
Access denied for user 'A101'@'%' to database 'hbr_scraper'
```
**原因**
- 使用者 `A101` 沒有建立資料庫的權限
- 資料庫 `HBR_scraper` 可能尚未建立
**解決方案**
#### 方案 A請資料庫管理員協助建立資料庫
請資料庫管理員執行以下 SQL
```sql
CREATE DATABASE IF NOT EXISTS `HBR_scraper` CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON `HBR_scraper`.* TO 'A101'@'%';
FLUSH PRIVILEGES;
```
然後執行:
```bash
python test_db_connection.py
```
#### 方案 B使用現有資料庫
如果已有其他資料庫可用,修改 `hbr_crawler/hbr_crawler/settings.py`
```python
DB_NAME = 'your_existing_database'
```
#### 方案 C暫時跳過資料庫儲存
系統會自動跳過資料庫儲存,僅產生 CSV 檔案。這不影響爬蟲的基本功能。
---
### 2. 爬蟲 URL 404 問題
**問題**
- 多個分類 URL 返回 404
- 只爬取到 1 個項目
**可能原因**
- 網站結構已改變
- URL 路徑不正確
**解決方案**
1. **檢查網站結構**
- 訪問 https://www.hbrtaiwan.com/ 查看實際的分類路徑
- 更新 `hbr_crawler/hbr_crawler/spiders/hbr.py` 中的 `start_urls`
2. **調整爬蟲邏輯**
- 可能需要更新 CSS 選擇器
- 檢查網站是否有反爬蟲機制
---
## 當前系統狀態
**正常運作的功能**
- Scrapy 爬蟲框架已安裝
- 爬蟲可以執行
- CSV 檔案可以產生
- 郵件發送功能(可選)
⚠️ **需要處理的問題**
- 資料庫連線(需要管理員權限建立資料庫)
- 爬蟲 URL 路徑(部分 URL 返回 404
---
## 建議處理順序
1. **先處理資料庫問題**(如果需要資料庫儲存):
- 請管理員建立資料庫
- 執行 `python test_db_connection.py` 驗證
2. **再處理爬蟲問題**
- 檢查網站實際結構
- 更新 `start_urls` 和 CSS 選擇器
3. **測試完整流程**
- 執行 `python run_crawler.py`
- 檢查 CSV 檔案和資料庫資料
---
## 臨時解決方案
如果暫時無法解決資料庫問題,系統仍可正常運作:
- ✅ 爬蟲會繼續執行
- ✅ CSV 檔案會正常產生
- ⚠️ 資料不會儲存到資料庫(但可以手動匯入 CSV
這不影響基本功能,只是資料不會自動儲存到資料庫。