added vpn ip rotation
This commit is contained in:
314
QUICKSTART_DE.md
Normal file
314
QUICKSTART_DE.md
Normal file
@@ -0,0 +1,314 @@
|
||||
# ProtonVPN-Integration für WebScraper: Quick-Start Guide
|
||||
|
||||
## 🚀 Schnelleinstieg (5 Minuten)
|
||||
|
||||
### 1. Konfiguration vorbereiten
|
||||
```bash
|
||||
# Copy .env.example zu .env
|
||||
cp .env.example .env
|
||||
|
||||
# Öffnen Sie .env und aktivieren Sie VPN:
|
||||
# ENABLE_VPN_ROTATION=true
|
||||
# VPN_SERVERS=US-Free#1,UK-Free#1,JP-Free#1
|
||||
# TASKS_PER_VPN_SESSION=5
|
||||
```
|
||||
|
||||
### 2. ProtonVPN-Extension installieren
|
||||
```bash
|
||||
# A. Automatisch (empfohlen):
|
||||
# Chrome öffnet die Extension automatisch beim ersten Browser-Start
|
||||
|
||||
# B. Manuell:
|
||||
# 1. Chrome öffnen
|
||||
# 2. chrome://extensions/ öffnen
|
||||
# 3. "ProtonVPN by Proton Technologies AG" suchen
|
||||
# 4. Installieren & Anmelden mit ProtonVPN-Account
|
||||
```
|
||||
|
||||
### 3. Extension-ID überprüfen
|
||||
```bash
|
||||
# 1. Chrome → chrome://extensions/
|
||||
# 2. ProtonVPN Details klicken
|
||||
# 3. Extension ID kopieren
|
||||
# 4. In .env eintragen:
|
||||
# PROTONVPN_EXTENSION_ID=ghmbeldphafepmbegfdlkpapadhbakde
|
||||
```
|
||||
|
||||
### 4. Cargo.toml überprüfen
|
||||
```toml
|
||||
[dependencies]
|
||||
fantoccini = { version = "0.20", features = ["rustls-tls"] }
|
||||
tokio = { version = "1.38", features = ["full"] }
|
||||
tracing = "0.1"
|
||||
tracing-subscriber = { version = "0.3", features = ["fmt", "env-filter"] }
|
||||
```
|
||||
|
||||
### 5. Projekt kompilieren & testen
|
||||
```bash
|
||||
# Kompilierung
|
||||
cargo build --release
|
||||
|
||||
# Mit Logging starten
|
||||
RUST_LOG=info cargo run
|
||||
|
||||
# Mit Debug-Logging:
|
||||
RUST_LOG=debug cargo run
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📋 Dateien-Struktur
|
||||
|
||||
Nach der Integration sollte Ihre Projektstruktur so aussehen:
|
||||
|
||||
```
|
||||
src/
|
||||
├── scraper/
|
||||
│ ├── mod.rs # ← Imports: vpn_session, protonvpn_extension, vpn_integration
|
||||
│ ├── webdriver.rs # (existierend, ggf. erweitert)
|
||||
│ ├── vpn_session.rs # ✨ NEU: Session-Manager
|
||||
│ ├── protonvpn_extension.rs # ✨ NEU: Extension-Automater
|
||||
│ └── vpn_integration.rs # ✨ NEU: Helper für Economic/Corporate
|
||||
├── config.rs # (erweitert mit VPN-Config)
|
||||
├── main.rs # (ggf. erweitert mit VPN-Calls)
|
||||
└── [economic/, corporate/, util/]
|
||||
|
||||
.env # ← Aktivieren Sie VPN hier
|
||||
.env.example # ← Template
|
||||
IMPLEMENTATION_GUIDE_DE.md # ← Detaillierte Anleitung
|
||||
INTEGRATION_EXAMPLE.md # ← Prakische Code-Beispiele
|
||||
TROUBLESHOOTING_DE.md # ← Problem-Lösungsguide
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## ✅ Checkliste: Integration Step-by-Step
|
||||
|
||||
### Phase 1: Vorbereitung
|
||||
- [ ] ProtonVPN-Account vorhanden (kostenlos ausreichend)
|
||||
- [ ] Chrome + ChromeDriver installiert
|
||||
- [ ] Rust Toolchain aktuell (`rustup update`)
|
||||
- [ ] Git Branch für Feature erstellt
|
||||
|
||||
```bash
|
||||
git checkout -b feature/browser-vpn
|
||||
```
|
||||
|
||||
### Phase 2: Dateien kopieren/erstellen
|
||||
- [ ] `src/scraper/vpn_session.rs` erstellt
|
||||
- [ ] `src/scraper/protonvpn_extension.rs` erstellt
|
||||
- [ ] `src/scraper/vpn_integration.rs` erstellt
|
||||
- [ ] `src/scraper/mod.rs` aktualisiert
|
||||
- [ ] `src/config.rs` mit VPN-Fields erweitert
|
||||
- [ ] `.env.example` erstellt
|
||||
|
||||
### Phase 3: Konfiguration
|
||||
- [ ] `.env` angelegt mit `ENABLE_VPN_ROTATION=false` (Testing)
|
||||
- [ ] ProtonVPN-Extension installiert
|
||||
- [ ] Extension-ID überprüft und in `.env` eingetragen
|
||||
- [ ] `Cargo.toml` Dependencies vollständig
|
||||
|
||||
### Phase 4: Testing
|
||||
- [ ] `cargo check` ohne Fehler
|
||||
- [ ] `cargo build` erfolgreich
|
||||
- [ ] `ENABLE_VPN_ROTATION=false cargo run` funktioniert (ohne VPN)
|
||||
- [ ] `ENABLE_VPN_ROTATION=true cargo run` mit VPN testen
|
||||
|
||||
### Phase 5: Integration in Economic/Corporate
|
||||
- [ ] `vpn_integration.rs` in economic Module importiert
|
||||
- [ ] `vpn_integration.rs` in corporate Module importiert
|
||||
- [ ] VPN-Checks in Task-Loops hinzugefügt
|
||||
- [ ] Tests mit `TASKS_PER_VPN_SESSION=1` durchgeführt
|
||||
|
||||
### Phase 6: Production
|
||||
- [ ] Mit `TASKS_PER_VPN_SESSION=10` getestet
|
||||
- [ ] Mit `MAX_PARALLEL_TASKS=3` oder höher getestet
|
||||
- [ ] Logs überprüft auf Fehler
|
||||
- [ ] Performance-Baseline etabliert
|
||||
|
||||
---
|
||||
|
||||
## 🧪 Testing-Szenarios
|
||||
|
||||
### Test 1: Ohne VPN (Baseline)
|
||||
```bash
|
||||
ENABLE_VPN_ROTATION=false MAX_PARALLEL_TASKS=1 RUST_LOG=info cargo run
|
||||
```
|
||||
**Erwartung:** Schnell, stabil, keine VPN-Logs
|
||||
|
||||
### Test 2: Mit VPN, ein Server
|
||||
```bash
|
||||
ENABLE_VPN_ROTATION=true VPN_SERVERS=US TASKS_PER_VPN_SESSION=10 MAX_PARALLEL_TASKS=1 RUST_LOG=info cargo run
|
||||
```
|
||||
**Erwartung:** Eine Session den ganzen Tag, gleiche IP
|
||||
|
||||
### Test 3: Mit VPN, Server-Rotation
|
||||
```bash
|
||||
ENABLE_VPN_ROTATION=true VPN_SERVERS=US,UK,JP TASKS_PER_VPN_SESSION=5 MAX_PARALLEL_TASKS=1 RUST_LOG=debug cargo run
|
||||
```
|
||||
**Erwartung:** Neue Session alle 5 Tasks, wechselnde IPs
|
||||
|
||||
### Test 4: Mit VPN, Parallel
|
||||
```bash
|
||||
ENABLE_VPN_ROTATION=true VPN_SERVERS=US,UK,JP MAX_PARALLEL_TASKS=3 TASKS_PER_VPN_SESSION=20 RUST_LOG=info cargo run
|
||||
```
|
||||
**Erwartung:** 3 parallele Tasks, nach 20 Tasks pro Instanz Rotation
|
||||
|
||||
---
|
||||
|
||||
## 🔍 Was wird wo integriert?
|
||||
|
||||
### `src/config.rs`
|
||||
```rust
|
||||
// Neue Fields:
|
||||
pub enable_vpn_rotation: bool,
|
||||
pub vpn_servers: String,
|
||||
pub tasks_per_vpn_session: usize,
|
||||
pub protonvpn_extension_id: String,
|
||||
|
||||
// Neue Methode:
|
||||
pub fn get_vpn_servers(&self) -> Vec<String>
|
||||
```
|
||||
|
||||
### `src/scraper/mod.rs`
|
||||
```rust
|
||||
pub mod vpn_session;
|
||||
pub mod protonvpn_extension;
|
||||
pub mod vpn_integration;
|
||||
```
|
||||
|
||||
### `src/main.rs` (optional, aber empfohlen)
|
||||
```rust
|
||||
let vpn_integration = VpnIntegration::from_config(&config)?;
|
||||
|
||||
if vpn_integration.enabled {
|
||||
vpn_integration.initialize_session().await?;
|
||||
}
|
||||
|
||||
// In Tasks:
|
||||
vpn_integration.check_and_rotate_if_needed().await?;
|
||||
vpn_integration.increment_task().await;
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 📊 Architektur-Übersicht
|
||||
|
||||
```
|
||||
┌─ main.rs
|
||||
│ └─ Config::load() ──────────┐
|
||||
│ │
|
||||
├─ VpnIntegration::from_config()
|
||||
│ ├─ VpnSessionManager::new()
|
||||
│ └─ ProtonVpnAutomater::new()
|
||||
│
|
||||
├─ ChromeDriverPool::new()
|
||||
│ └─ ChromeInstance (mit Extension)
|
||||
│ └─ fantoccini::Client
|
||||
│
|
||||
└─ Task Loop
|
||||
├─ vpn.check_and_rotate_if_needed()
|
||||
├─ pool.execute(task)
|
||||
│ └─ client.goto(url) + scraping
|
||||
└─ vpn.increment_task()
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🐛 Häufigste Fehler & Lösungen
|
||||
|
||||
| Fehler | Lösung |
|
||||
|--------|--------|
|
||||
| `Failed to navigate to chrome-extension://...` | Extension nicht installiert oder falsche ID |
|
||||
| `Button 'connect' not found` | Extension-Version hat sich geändert, Selektoren aktualisieren (TROUBLESHOOTING_DE.md) |
|
||||
| `Failed to extract IP from page` | Alternative IP-Check-Service verwenden (icanhazip.com, ifconfig.me) |
|
||||
| `Semaphore closed` | ChromeDriver-Pool zu klein oder zu viele parallele Tasks |
|
||||
| `Timeout connecting to server` | Netzwerk-Latenz oder ProtonVPN-Server überlastet, Timeout erhöhen |
|
||||
|
||||
→ Weitere Details: **TROUBLESHOOTING_DE.md**
|
||||
|
||||
---
|
||||
|
||||
## 📚 Dokumentation
|
||||
|
||||
1. **IMPLEMENTATION_GUIDE_DE.md** - Umfassende Anleitung mit Theorie & Architektur
|
||||
2. **INTEGRATION_EXAMPLE.md** - Praktische Code-Beispiele für Ihr Projekt
|
||||
3. **TROUBLESHOOTING_DE.md** - Fehlerbehandlung & FAQ
|
||||
4. **Dieses README** - Quick-Start
|
||||
|
||||
---
|
||||
|
||||
## 🎯 Nächste Schritte
|
||||
|
||||
1. **Integration in Economic Module:**
|
||||
```rust
|
||||
// src/economic/mod.rs
|
||||
use scraper::vpn_integration::VpnIntegration;
|
||||
|
||||
pub async fn run_full_update_with_vpn(
|
||||
config: &Config,
|
||||
pool: &Arc<ChromeDriverPool>,
|
||||
vpn: &VpnIntegration,
|
||||
) -> Result<()> {
|
||||
// für jeden Task:
|
||||
if vpn.check_and_rotate_if_needed().await? {
|
||||
sleep(Duration::from_secs(2)).await;
|
||||
}
|
||||
// ... task execution ...
|
||||
vpn.increment_task().await;
|
||||
}
|
||||
```
|
||||
|
||||
2. **Integration in Corporate Module:**
|
||||
- Analog zu Economic
|
||||
|
||||
3. **Performance-Tuning:**
|
||||
```env
|
||||
# Nach Bedarf anpassen:
|
||||
MAX_PARALLEL_TASKS=3 # Start mit 3
|
||||
TASKS_PER_VPN_SESSION=10 # Ballance zwischen IP-Rotation & Performance
|
||||
MAX_TASKS_PER_INSTANCE=0 # 0 = unlimited (einfacher für Anfang)
|
||||
```
|
||||
|
||||
4. **Monitoring:**
|
||||
```bash
|
||||
# Logs speichern für Analyse
|
||||
RUST_LOG=info cargo run > scraper.log 2>&1
|
||||
|
||||
# Statistiken beobachten:
|
||||
tail -f scraper.log | grep "Session\|IP\|Connected"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 🚨 Wichtige Hinweise
|
||||
|
||||
⚠️ **Browser muss für Extension-Automatisierung sichtbar sein**
|
||||
- Headless-Mode funktioniert teilweise nicht mit Extension-UI
|
||||
- Bei Tests ohne Headless starten für besseres Debugging
|
||||
|
||||
⚠️ **ProtonVPN-Account nötig**
|
||||
- Kostenlos (Free) reicht aus für diese Integration
|
||||
- Free-Tier hat limitierte Server
|
||||
|
||||
⚠️ **IP-Rotation nicht garantiert**
|
||||
- Load-Balancing auf ProtonVPN-Servern kann zu ähnlichen IPs führen
|
||||
- Typischerweise aber unterschiedlich genug für Website-Scraping
|
||||
|
||||
⚠️ **Rate-Limiting beachten**
|
||||
- VPN ändert nur Browser-Traffic, nicht Rate-Limits der Website
|
||||
- Zielwebsite sieht trotzdem parallele Requests von "ähnlicher IP"
|
||||
- Lösung: Tasks sequenziell ausführen oder Delays erhöhen
|
||||
|
||||
---
|
||||
|
||||
## 📞 Support
|
||||
|
||||
Für Fragen:
|
||||
1. Lesen Sie zuerst **TROUBLESHOOTING_DE.md**
|
||||
2. Überprüfen Sie `RUST_LOG=debug cargo run` Output
|
||||
3. Nutzen Sie `cargo test` für Unit Tests
|
||||
|
||||
---
|
||||
|
||||
**Viel Erfolg mit der ProtonVPN-Integration! 🎉**
|
||||
Reference in New Issue
Block a user