-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
217 lines (192 loc) · 7.99 KB
/
Copy pathconfig.py
File metadata and controls
217 lines (192 loc) · 7.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
"""
Google Maps Scraper Konfigürasyon Modülü
Bu modül tüm sabit değerleri, ayarları ve konfigürasyonları içerir.
Değişiklik yapmak için sadece bu dosyayı edit etmek yeterlidir.
"""
import logging
from datetime import datetime
# ============================================================================
# LOGGING AYARLARI (Orijinal kodun 15. satırından)
# ============================================================================
LOGGING_LEVEL = logging.INFO
LOGGING_FORMAT = '%(asctime)s - %(levelname)s - %(message)s'
# ============================================================================
# WEBDRIVER AYARLARI (Orijinal kodun 23. ve 29-35. satırlarından)
# ============================================================================
DEFAULT_CHROMEDRIVER_PATH = "/usr/bin/chromedriver"
# Chrome Browser Seçenekleri
CHROME_OPTIONS = [
"--start-maximized",
"--disable-blink-features=AutomationControlled",
"--lang=en-US", # İngilizce dil zorlaması
"--user-data-dir=/tmp/chrome_test_profile", # Temiz profil
"--no-first-run", # İlk çalıştırma kurulumunu atla
"--disable-default-apps", # Varsayılan uygulamaları devre dışı bırak
#"--headless", # Headless mod (görünmez tarayıcı)
"--disable-extensions",
"--disable-plugins",
"--disable-images", # YENİ: Resim yükleme kapalı
"--disable-javascript", # YENİ: JS kapalı (sadece gerekli)
"--no-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--disable-web-security",
]
CHROME_EXPERIMENTAL_OPTIONS = {
"excludeSwitches": ["enable-automation"],
"useAutomationExtension": False,
"prefs": {
"intl.accept_languages": "en-US,en",
"profile.default_content_setting_values.notifications": 2,
"profile.managed_default_content_settings.images": 2, # YENİ: Resimler kapalı
"profile.default_content_settings.popups": 0,
}
}
# Anti-detection script
ANTI_DETECTION_SCRIPT = "Object.defineProperty(navigator, 'webdriver', {get: () => undefined})"
# ============================================================================
# SAYFA YÜKLENİR AYARLARI (Orijinal kodun 38-50. satırlarından)
# ============================================================================
PAGE_LOAD_TIMEOUT = 2.5 # Sayfa yükleme timeout (saniye)
GOOGLE_MAPS_LOAD_WAIT = 1.5 # Google Maps'in yüklenmesi için ekstra bekleme
SCROLL_PAUSE_TIME = 0.2
# ============================================================================
# SCROLL VE YORUM ÇEKME AYARLARI (Orijinal kodun 87. ve 296. satırlarından)
# ============================================================================
class ScrollConfig:
# Normal scroll ayarları
MAX_SCROLLS = 20
TARGET_REVIEW_COUNT = None
SCROLL_WAIT_TIME = 1.5
# Agresif scroll ayarları
AGGRESSIVE_MAX_SCROLLS = 300
CONSECUTIVE_NO_CHANGE_LIMIT = 3
STAGNANT_SCROLLS_LIMIT = 10
# Dinamik bekleme süreleri
FAST_LOAD_WAIT = 1 # Hızlı yükleme için
NORMAL_LOAD_WAIT = 1.5 # Normal yükleme için
SLOW_LOAD_WAIT = 2 # Yavaş yükleme için
# ============================================================================
# CSS SELECTOR'LAR (Orijinal kodda dağınık halde)
# ============================================================================
class Selectors:
# Ana container'lar
REVIEWS_TAB = "[data-value='Reviews']"
MAIN_ROLE = "[role='main']"
BODY_TAG = "body"
# Yorum elementleri - orijinal kodun 385-396. satırlarından
REVIEW_CONTAINERS = [
"div.jftiEf",
"div.MyEned",
"div[data-review-id]",
"div.m6QErb.XiKgde",
"div[jslog*='review']",
"div.gws-localreviews__google-review",
"div.ODSEW-ShBeI",
"div[data-ved] div[data-review]",
"div.review-item",
"div[class*='review']"
]
# Yorum içeriği - orijinal kodun 155-177. satırlarından
PROFILE_NAME = "div.d4r55.fontTitleMedium"
RATING_ELEMENT = "[role='img'][aria-label*='yıldız']"
COMMENT_TEXT = [
"span.wiI7pd",
".MyEned span.wiI7pd",
"[data-expandable-section] span",
".review-text span",
"span[jslog*='review']"
]
DATE_ELEMENT = ".rsqaWe"
LANGUAGE_ELEMENT = "div.MyEned[lang]"
CONTRIBUTION_ELEMENT = ".RfnDt"
# More button - orijinal kodun 110-119. satırlarından
MORE_BUTTON_SELECTORS = [
# CSS SELECTORS - Önce bunlar denensin
"button.w8nwRe.kyuRq",
"button[aria-label='See more']",
"button[aria-expanded='false']",
"button[jsaction*='expandReview']", # Virgül eklendi
"button[data-expandable='true']",
"button[jsaction*='review.expandReview']",
"span.w8nwRe[role='button']",
".w8nwRe",
"button.review-more-link",
# XPATH SELECTORS - Sonra bunlar denensin
"//button[contains(text(), 'More')]",
"//button[contains(text(), 'Daha fazla')]",
"//button[contains(text(), 'Más')]",
"//button[contains(text(), 'Plus')]",
"//button[contains(text(), 'Mehr')]",
"//button[contains(text(), 'Di più')]",
"//button[contains(text(), 'Mais')]",
"//button[contains(text(), 'Больше')]",
"//button[contains(text(), 'もっと')]",
"//button[contains(text(), '더보기')]",
"//button[contains(text(), '更多')]",
"//span[@role='button' and contains(text(), 'More')]",
"//span[@role='button' and contains(text(), 'Daha fazla')]",
"//span[contains(@class, 'w8nwRe') and contains(text(), 'More')]",
]
# Class seviyesinde constant olarak tanımla
ORIGINAL_CONTENT_BUTTON_SELECTORS = [
# CSS Selectors
"button[jsaction*='showReviewInOriginal']",
"button.kyuRq.fontTitleSmall.WOKzJe",
"button[aria-controls*='CIHM']",
# XPath Selectors
"//button[contains(., 'Orijinal içeriği göster')]",
"//button[contains(., 'Show original')]",
"//button[contains(., 'Original anzeigen')]",
"//button[contains(., 'Mostrar original')]",
"//button[contains(., 'Afficher l'original')]",
]
# Scroll container'lar - orijinal kodun 325-333. satırlarından
SCROLL_CONTAINERS = [
"div[data-ved] div[style*='overflow']",
".m6QErb div[style*='overflow-y']",
"div[data-attrid*='scrollable']",
".section-scrollbox",
"[role='main'] div[style*='overflow']",
"div.m6QErb.DxyBCb.kA9KIf.dS8AEf"
]
# ============================================================================
# DOSYA AYARLARI
# ============================================================================
class FileConfig:
CSV_ENCODING = "utf-8"
JSON_ENCODING = "utf-8"
JSON_INDENT = 2
# CSV field names - orijinal kodun 456. satırından
CSV_FIELDNAMES = [
'profile_name', 'score', 'comment', 'language',
'contribution', 'date', 'url', 'scraped_at'
]
# ============================================================================
# VARSAYILAN DEĞERLER
# ============================================================================
class Defaults:
PROFILE_NAME = "Anonim"
SCORE = "Puan yok"
COMMENT = ""
DATE = "Tarih bilinmiyor"
LANGUAGE = "none"
CONTRIBUTION = "Bilinmiyor"
SAFE_GET_TEXT = ""
# ============================================================================
# REGEX PATTERN'LER (Orijinal kodun 253. satırından)
# ============================================================================
REVIEW_COUNT_PATTERN = r'([\d,]+)\s+reviews?'
# ============================================================================
# UTILITY FUNCTIONS
# ============================================================================
def get_current_timestamp():
"""Mevcut zaman damgası"""
return datetime.now().isoformat()
def setup_logging():
"""Logging'i ayarla"""
logging.basicConfig(
level=LOGGING_LEVEL,
format=LOGGING_FORMAT
)
return logging.getLogger(__name__)