-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNaverBlog_comments_collector.py
More file actions
534 lines (432 loc) Β· 21.4 KB
/
NaverBlog_comments_collector.py
File metadata and controls
534 lines (432 loc) Β· 21.4 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
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
# Standard library imports
import os
import re
import time
import threading
import tkinter as tk
from tkinter import ttk, filedialog, scrolledtext
from datetime import datetime
import queue
# Third party imports
from bs4 import BeautifulSoup
import pandas as pd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
import subprocess
class NaverBlogCommentCollector:
def __init__(self, root):
self.root = root
self.root.title("λ€μ΄λ² λΈλ‘κ·Έ λκΈ μμ§κΈ° v2025.05.12")
self.root.geometry("700x550")
self.root.resizable(True, True)
# λ³μ μ€μ
self.version = "2025-05-12 00:00:00"
self.user = os.getlogin()
self.is_running = False
self.driver = None
self.log_queue = queue.Queue()
self.default_save_path = os.path.join(os.path.expanduser("~"), "Desktop", "naver_blog_λκΈμμ§.xlsx")
# μ€νμΌ μ€μ
style = ttk.Style()
style.configure("TButton", padding=6, relief="flat", background="#ccc")
style.configure("TLabel", padding=6)
style.configure("TFrame", padding=10)
self.create_widgets()
self.setup_logging()
def create_widgets(self):
# λ©μΈ νλ μ
main_frame = ttk.Frame(self.root)
main_frame.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
# URL μ
λ ₯ μΉμ
url_frame = ttk.Frame(main_frame)
url_frame.pack(fill=tk.X, pady=5)
ttk.Label(url_frame, text="λΈλ‘κ·Έ κ²μκΈ URL:").pack(side=tk.LEFT)
self.url_entry = ttk.Entry(url_frame, width=50)
self.url_entry.pack(side=tk.LEFT, padx=5, fill=tk.X, expand=True)
# μ΅μ
μΉμ
option_frame = ttk.Frame(main_frame)
option_frame.pack(fill=tk.X, pady=5)
ttk.Label(option_frame, text="λΈλ‘κ·Έ μμ μ£Ό μ¬λΆ:").pack(side=tk.LEFT)
self.owner_var = tk.StringVar(value="n")
ttk.Radiobutton(option_frame, text="μ", variable=self.owner_var, value="y").pack(side=tk.LEFT, padx=5)
ttk.Radiobutton(option_frame, text="μλμ€", variable=self.owner_var, value="n").pack(side=tk.LEFT, padx=5)
# νμΌ μ μ₯ μμΉ μΉμ
save_frame = ttk.Frame(main_frame)
save_frame.pack(fill=tk.X, pady=5)
ttk.Label(save_frame, text="μ μ₯ μμΉ:").pack(side=tk.LEFT)
self.save_path_var = tk.StringVar(value=self.default_save_path)
self.save_path_entry = ttk.Entry(save_frame, textvariable=self.save_path_var, width=50)
self.save_path_entry.pack(side=tk.LEFT, padx=5, fill=tk.X, expand=True)
browse_btn = ttk.Button(save_frame, text="μ°Ύμ보기", command=self.browse_save_location)
browse_btn.pack(side=tk.LEFT, padx=5)
# λ‘κ·Έ μ°½
log_frame = ttk.Frame(main_frame)
log_frame.pack(fill=tk.BOTH, expand=True, pady=5)
ttk.Label(log_frame, text="λ‘κ·Έ:").pack(anchor=tk.W)
self.log_text = scrolledtext.ScrolledText(log_frame, height=15, wrap=tk.WORD)
self.log_text.pack(fill=tk.BOTH, expand=True)
self.log_text.config(state=tk.DISABLED)
# λ²νΌ μΉμ
button_frame = ttk.Frame(main_frame)
button_frame.pack(fill=tk.X, pady=10)
self.start_btn = ttk.Button(button_frame, text="μ€ν", command=self.start_collection)
self.start_btn.pack(side=tk.LEFT, padx=5)
self.stop_btn = ttk.Button(button_frame, text="μ€μ§", command=self.stop_collection, state=tk.DISABLED)
self.stop_btn.pack(side=tk.LEFT, padx=5)
self.open_file_btn = ttk.Button(button_frame, text="νμΌ μμΉ μ΄κΈ°", command=self.open_file_location,
state=tk.DISABLED)
self.open_file_btn.pack(side=tk.LEFT, padx=5)
# μν νμμ€
self.status_var = tk.StringVar(value="μ€λΉλ¨")
status_bar = ttk.Label(self.root, textvariable=self.status_var, relief=tk.SUNKEN, anchor=tk.W)
status_bar.pack(side=tk.BOTTOM, fill=tk.X)
def setup_logging(self):
# λ‘κ·Έ μ
λ°μ΄νΈ ν¨μ
def update_log():
while True:
try:
record = self.log_queue.get(block=False)
self.log_text.config(state=tk.NORMAL)
self.log_text.insert(tk.END, record + "\n")
self.log_text.see(tk.END)
self.log_text.config(state=tk.DISABLED)
self.log_queue.task_done()
except queue.Empty:
break
self.root.after(100, update_log)
# λ‘κ·Έ μ
λ°μ΄νΈ μμ
self.root.after(100, update_log)
def log(self, message):
self.log_queue.put(f"[{datetime.now().strftime('%H:%M:%S')}] {message}")
def browse_save_location(self):
filename = filedialog.asksaveasfilename(
initialdir=os.path.dirname(self.save_path_var.get()),
initialfile=os.path.basename(self.save_path_var.get()),
defaultextension=".xlsx",
filetypes=[("Excel νμΌ", "*.xlsx"), ("λͺ¨λ νμΌ", "*.*")]
)
if filename:
self.save_path_var.set(filename)
def start_collection(self):
if not self.url_entry.get().strip():
self.log("μ€λ₯: URLμ μ
λ ₯ν΄μ£ΌμΈμ.")
return
self.is_running = True
self.start_btn.config(state=tk.DISABLED)
self.stop_btn.config(state=tk.NORMAL)
self.open_file_btn.config(state=tk.DISABLED)
self.status_var.set("μ€ν μ€...")
# λ³λ μ€λ λμμ μ€ν
threading.Thread(target=self.collect_comments, daemon=True).start()
def stop_collection(self):
self.is_running = False
self.log("μ¬μ©μμ μν΄ μμ
μ΄ μ€μ§λμμ΅λλ€.")
self.status_var.set("μ€μ§λ¨")
if self.driver:
try:
self.driver.quit()
except:
pass
self.driver = None
self.start_btn.config(state=tk.NORMAL)
self.stop_btn.config(state=tk.DISABLED)
def open_file_location(self):
save_path = self.save_path_var.get()
if os.path.exists(save_path):
try:
# νμΌ νμκΈ°μμ νμΌ μ ννμ¬ μ΄κΈ°
if os.name == 'nt': # Windows
subprocess.Popen(f'explorer /select,"{save_path}"')
elif os.name == 'posix': # macOS, Linux
if 'darwin' in os.sys.platform: # macOS
subprocess.Popen(['open', '-R', save_path])
else: # Linux
subprocess.Popen(['xdg-open', os.path.dirname(save_path)])
except Exception as e:
self.log(f"νμΌ μμΉλ₯Ό μ΄ μ μμ΅λλ€: {str(e)}")
else:
self.log("νμΌμ΄ μ‘΄μ¬νμ§ μμ΅λλ€.")
def collect_comments(self):
try:
self.log(f"λ€μ΄λ² λΈλ‘κ·Έ λκΈμμ§ νλ‘κ·Έλ¨ v{self.version} μμ")
# ν¬λ‘¬ λλΌμ΄λ² μ€μ
options = Options()
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
options.add_argument(f"user-agent={user_agent}")
# λ‘κ·ΈμΈ νμ μ¬λΆ νμΈ
is_owner = self.owner_var.get() == "y"
if is_owner:
self.log("λΈλ‘κ·Έ μμ μ£Ό λͺ¨λλ‘ μ€νν©λλ€ (λ‘κ·ΈμΈ νμ)")
# λ‘κ·ΈμΈμ μν΄ ν€λλ¦¬μ€ λͺ¨λ λΉνμ±ν
self.driver = webdriver.Chrome(options=options)
self.driver.get("https://nid.naver.com/nidlogin.login?mode=form&url=https://www.naver.com/")
# λ‘κ·ΈμΈ λκΈ°
self.log("λ€μ΄λ² λ‘κ·ΈμΈ νμ΄μ§κ° μ΄λ Έμ΅λλ€. λ‘κ·ΈμΈμ μλ£ν΄μ£ΌμΈμ.")
self.root.after(0, lambda: self.show_login_dialog())
return
else:
self.log("λΉμμ μ£Ό λͺ¨λλ‘ μ€νν©λλ€ (λ‘κ·ΈμΈ λΆνμ)")
options.add_argument("--headless") # ν€λλ¦¬μ€ λͺ¨λ
self.driver = webdriver.Chrome(options=options)
self.process_url()
except Exception as e:
self.log(f"μ€λ₯ λ°μ: {str(e)}")
self.stop_collection()
def show_login_dialog(self):
login_dialog = tk.Toplevel(self.root)
login_dialog.title("λ‘κ·ΈμΈ νμΈ")
login_dialog.geometry("300x150")
login_dialog.transient(self.root)
login_dialog.grab_set()
ttk.Label(login_dialog, text="λ€μ΄λ² λ‘κ·ΈμΈμ μλ£νμ
¨λμ?").pack(pady=20)
btn_frame = ttk.Frame(login_dialog)
btn_frame.pack(pady=10)
ttk.Button(btn_frame, text="μλ£", command=lambda: self.login_completed(login_dialog)).pack(side=tk.LEFT, padx=10)
ttk.Button(btn_frame, text="μ·¨μ", command=lambda: self.login_cancelled(login_dialog)).pack(side=tk.LEFT, padx=10)
def login_completed(self, dialog):
dialog.destroy()
# λ‘κ·ΈμΈ μλ£ ν μΏ ν€ μμ§
self.log("λ‘κ·ΈμΈ μ 보 μ μ₯ μ€...")
cookies = self.driver.get_cookies()
# κΈ°μ‘΄ λΈλΌμ°μ μ’
λ£
self.driver.quit()
self.driver = None
# μλ‘μ΄ headless λΈλΌμ°μ μμ±
options = Options()
user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36"
options.add_argument(f"user-agent={user_agent}")
options.add_argument("--headless=new") # μ΅μ headless λͺ¨λ μ¬μ©
self.log("λ°±κ·ΈλΌμ΄λ λͺ¨λλ‘ μ ν μ€...")
self.driver = webdriver.Chrome(options=options)
# λ€μ΄λ² λλ©μΈ λ°©λ¬Έ (μΏ ν€ μ€μ μ μν΄)
self.driver.get("https://www.naver.com")
# μ μ₯λ μΏ ν€ μ μ©
for cookie in cookies:
# μΌλΆ μΏ ν€ μμ±μ μΆκ°ν λ λ¬Έμ λ₯Ό μΌμΌν¬ μ μμ΄ μ κ±°
if 'expiry' in cookie:
del cookie['expiry']
try:
self.driver.add_cookie(cookie)
except Exception as e:
self.log(f"μΏ ν€ μ€μ μ€ μ€λ₯ λ°μ: {str(e)}")
self.log("λ‘κ·ΈμΈ μ 보 μ μ© μλ£")
self.process_url()
def login_cancelled(self, dialog):
dialog.destroy()
self.stop_collection()
def convert_mobile_to_desktop_url(self, url):
"""λͺ¨λ°μΌ URLμ λ°μ€ν¬ν λ²μ μΌλ‘ λ³ν"""
try:
# λͺ¨λ°μΌ URL ν¨ν΄ νμΈ λ° λ³ν
if "m.blog.naver.com" in url:
# m.blog.naver.comμ blog.naver.comμΌλ‘ λ³ν
desktop_url = url.replace("m.blog.naver.com", "blog.naver.com")
# referrerCodeμ κ°μ λΆνμν νλΌλ―Έν° μ κ±°
if "?" in desktop_url:
desktop_url = desktop_url.split("?")[0]
self.log(f"λͺ¨λ°μΌ URLμ λ°μ€ν¬ν λ²μ μΌλ‘ λ³ν: {url} -> {desktop_url}")
return desktop_url
# μ΄λ―Έ λ°μ€ν¬ν λ²μ μ΄κ±°λ λ€λ₯Έ νμμΈ κ²½μ° κ·Έλλ‘ λ°ν
return url
except Exception as e:
self.log(f"URL λ³ν μ€ μ€λ₯ λ°μ: {str(e)}")
return url
def process_url(self):
if not self.is_running:
return
url = self.url_entry.get().strip()
self.log(f"μ
λ ₯λ URL: {url}")
# λͺ¨λ°μΌ URLμ λ°μ€ν¬ν λ²μ μΌλ‘ λ³ν
url = self.convert_mobile_to_desktop_url(url)
self.log(f"λ³νλ URL: {url}")
try:
# κ²μλ¬Ό μμ΄λ μΆμΆ
try:
self.log("URL νμ λΆμ μ€ (method1)")
blog_id = re.search(r'blogId=([^&]+)', url).group(1)
extracted_number = re.search(r'logNo=([^&]+)', url).group(1)
url = f"https://blog.naver.com/{blog_id}/{extracted_number}"
self.log("URL λ³ν μλ£")
except:
self.log("method1 μ€ν¨, method2 μλ μ€")
try:
split_url = url.split("com/")[1]
blog_id, extracted_number = split_url.split("/")
self.log("URL λ³ν μλ£")
except:
self.log("URL ν¨ν΄μ μΈμν μ μμ΅λλ€.")
self.stop_collection()
return
# λͺ¨λ°μΌ λκΈ νμ΄μ§λ‘ λ³ν
mobile_url = f"https://m.blog.naver.com/CommentList.naver?blogId={blog_id}&logNo={extracted_number}"
self.log(f"λͺ¨λ°μΌ λκΈ νμ΄μ§ URL: {mobile_url}")
# νμ΄μ§ λ‘λ
self.log("λκΈ νμ΄μ§ λ‘λ© μ€...")
self.driver.get(mobile_url)
# μ€ν¬λ‘€νμ¬ λͺ¨λ λκΈ λ‘λ
self.log("λͺ¨λ λκΈμ λ‘λνκΈ° μν΄ μ€ν¬λ‘€ μ€...")
time.sleep(2)
self.driver.execute_script("window.scrollTo(0, 0);")
last_height = 0
for _ in range(10): # μ΅λ 10λ² μ€ν¬λ‘€ μλ
if not self.is_running:
return
current_height = self.driver.execute_script("return document.body.scrollHeight")
if current_height == last_height:
break
# νμ΄μ§ λκΉμ§ μ€ν¬λ‘€
self.driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(1)
last_height = current_height
# λκΈ λ°μ΄ν° μμ§
self.log("λκΈ λ°μ΄ν° μμ§ μ€...")
html = self.driver.page_source
soup = BeautifulSoup(html, 'html.parser')
# λλΌμ΄λ² μ’
λ£
self.driver.quit()
self.driver = None
# λκΈ νμ±
c_save = self.parse_comments(soup)
if not c_save:
self.log("μμ§λ λκΈμ΄ μμ΅λλ€.")
self.stop_collection()
return
# λ°μ΄ν°νλ μμΌλ‘ λ³ν
self.log(f"μ΄ {len(c_save)}κ°μ λκΈμ μμ§νμ΅λλ€.")
df = pd.DataFrame(c_save, columns=["λλκΈ μ¬λΆ", "λμ΄μ΄", "λμ΄μ΄ URL", "λ μ§", "λκΈ λ΄μ©", "κ³΅κ° μ", "λκΈ λ΄ λ§ν¬", "λκΈ λ΄ μ΄λ©μΌ",
"λκΈ λ΄ μ΄λ―Έμ§"])
# νμΌ μ μ₯
save_path = self.save_path_var.get()
save_path = self.ensure_unique_filename(save_path)
df.to_excel(save_path, index=False)
self.log(f"νμΌ μ μ₯ μλ£: {save_path}")
# μμ
μλ£ ν UI μ
λ°μ΄νΈ
self.root.after(0, self.collection_completed, save_path)
except Exception as e:
self.log(f"μ€λ₯ λ°μ: {str(e)}")
if self.driver:
self.driver.quit()
self.driver = None
self.root.after(0, self.stop_collection)
def parse_comments(self, soup):
c_save = []
try:
c_list_css_selector = '#naverComment_wai_u_cbox_content_wrap_tabpanel > ul'
c_list = soup.select(c_list_css_selector)
if not c_list:
self.log("λκΈ λͺ©λ‘μ μ°Ύμ μ μμ΅λλ€.")
return c_save
# c_list λ΄μ κ° li μμ μ ν
rows = c_list[0].find_all('li')
self.log(f"λκΈ {len(rows)}κ° λ°κ²¬")
for idx, row in enumerate(rows):
if not self.is_running:
return c_save
self.log(f"λκΈ {idx + 1}/{len(rows)} μ²λ¦¬ μ€")
# λλκΈ μ¬λΆ νμΈ
if row.find('div').find(class_="u_cbox_ico_reply"):
nested_comment = 'O'
else:
nested_comment = 'X'
# λκΈ λ¨ μ¬λ μ΄λ¦
c_id_css_selector = "div:nth-child(1) div div:nth-child(2) span:nth-child(1)"
c_id_element = row.select_one(c_id_css_selector)
if c_id_element is None or c_id_element.text == "":
c_id_css_selector = ".u_cbox_reply_area > ul > li > div > div > div.u_cbox_info > span.u_cbox_info_main > a > span > span > span"
c_id_element = row.select_one(c_id_css_selector)
if c_id_element is None or c_id_element.text == "":
c_id = "μ΅λͺ
"
else:
c_id = c_id_element.text
else:
c_id = c_id_element.text
# λκΈ λ¨ μ¬λμ λΈλ‘κ·Έ μ£Όμ
c_id_url_css_selector = '.u_cbox_comment_box.u_cbox_type_profile > div > div.u_cbox_info > span.u_cbox_info_main > a'
c_id_url_element = row.select_one(c_id_url_css_selector)
c_id_url = str(c_id_url_element['href']) if c_id_url_element else "μ΅λͺ
"
# λκΈ λ¨ λ μ§
try:
c_date_css_selector = "div:nth-child(1) div div:nth-child(3) span"
c_date_pre1 = row.select_one(c_date_css_selector).text
c_date_pre2 = datetime.strptime(c_date_pre1, '%Y.%m.%d. %H:%M')
c_date = str(c_date_pre2.strftime('%Y-%m-%d %H:%M'))
except:
try:
c_date_css_selector = "div:nth-child(1) > div > div:nth-child(4) > span"
c_date_pre1 = row.select_one(c_date_css_selector).text
c_date_pre2 = datetime.strptime(c_date_pre1, '%Y.%m.%d. %H:%M')
c_date = str(c_date_pre2.strftime('%Y-%m-%d %H:%M'))
except:
c_date = "9999-01-01 00:00"
# λκΈ λ΄μ©
c_content_css_selector = "div:nth-child(1) > div > div:nth-child(2) > span:nth-child(1)"
c_content_element = row.select_one(c_content_css_selector)
if c_content_element:
c_content = c_content_element.text
try:
date_format = "%Y.%m.%d. %H:%M"
c_date = datetime.strptime(c_content, date_format)
c_content = "λΉλ° λκΈμ
λλ€."
except ValueError:
pass
else:
c_content = "λ΄μ©μ λΆλ¬μ¬ μ μμ΅λλ€"
# λκΈ μ’μμ μ
c_likes_css_selector = "div:nth-child(1) div div:nth-child(4) div a em"
c_likes_element = row.select_one(c_likes_css_selector)
c_likes = int(c_likes_element.text) if c_likes_element else 0
# λκΈ λ΄ μ΄λ―Έμ§ λ§ν¬
comment_img_css_selector = 'div > div > div:nth-child(3) > div > a > img'
comment_img_element = row.select_one(comment_img_css_selector)
comment_img = str(comment_img_element['src']) if comment_img_element else "X"
if "?type=" in comment_img:
comment_img = comment_img.split('?type=')[0]
# λκΈ λ΄ λ§ν¬ λ° μ΄λ©μΌ 체ν¬
if "www" in c_content or "http" in c_content:
link_regex = r'(www\.[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})|(https?://\S+)'
c_links_pre = str(re.findall(link_regex, c_content))
remove_chars = {"[": None, "]": None, "(": None, ")": None, "'": None, '"': None}
c_links = c_links_pre.translate(str.maketrans(remove_chars))[2:].replace(", ,", ",")
if not c_links:
c_links = "X"
else:
c_links = "X"
if "@" in c_content[1:]:
email_regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
c_email_pre = str(re.findall(email_regex, c_content))
remove_chars = {"[": None, "]": None, "(": None, ")": None, "'": None, '"': None}
c_email = c_email_pre.translate(str.maketrans(remove_chars))
if not c_email:
c_email = "X"
else:
c_email = "X"
c_save.append(
(nested_comment, c_id, c_id_url, c_date, c_content, c_likes, c_links, c_email, comment_img))
except Exception as e:
self.log(f"λκΈ νμ± μ€ μ€λ₯ λ°μ: {str(e)}")
return c_save
def ensure_unique_filename(self, filepath):
"""νμΌλͺ
μ΄ μ€λ³΅λμ§ μλλ‘ μ²λ¦¬"""
directory = os.path.dirname(filepath)
filename = os.path.basename(filepath)
name, ext = os.path.splitext(filename)
counter = 1
while os.path.exists(filepath):
filepath = os.path.join(directory, f"{name}({counter}){ext}")
counter += 1
return filepath
def collection_completed(self, save_path):
self.is_running = False
self.status_var.set("μλ£λ¨")
self.start_btn.config(state=tk.NORMAL)
self.stop_btn.config(state=tk.DISABLED)
self.open_file_btn.config(state=tk.NORMAL)
self.log("μμ
μ΄ μλ£λμμ΅λλ€.")
def main():
root = tk.Tk()
app = NaverBlogCommentCollector(root)
root.mainloop()
if __name__ == "__main__":
main()