Skip to content

Instantly share code, notes, and snippets.

@blood72
Created May 30, 2021 11:05
Show Gist options
  • Save blood72/a75f98c251df5a5a1ec61261c034dd59 to your computer and use it in GitHub Desktop.
Save blood72/a75f98c251df5a5a1ec61261c034dd59 to your computer and use it in GitHub Desktop.
2018-10-15~2018-11-02 와룡전설 이벤트 글 추적기 (python 3.5)
from bs4 import BeautifulSoup
from tkinter import Tk, Label, IntVar, Entry, Button
import requests
import ctypes
import win32process
import os
import sys
# variables
base_url = "http://wa.ilovegame.co.kr/event/read/"
first_page = 1
hwnd = ctypes.windll.kernel32.GetConsoleWindow()
if hwnd != 0:
ctypes.windll.user32.ShowWindow(hwnd, 0)
ctypes.windll.kernel32.CloseHandle(hwnd)
_, pid = win32process.GetWindowThreadProcessId(hwnd)
os.system('taskkill /PID ' + str(pid) + ' /f')
# GUI
def dialog():
root = Tk()
root.title('와룡전설 이벤트글 추적기')
root.geometry('320x120')
def validate(str, action_type):
if action_type == '1': # insert
if not str.isdigit():
return False
return True
label_f = Label(root, text="여기부터")
label_f.pack()
var_f = IntVar()
var_f.set(first_page)
entry_f = Entry(root, textvariable=var_f, validate='key')
entry_f['validatecommand'] = (entry_f.register(validate), '%P', '%d')
entry_f.pack()
label_e = Label(root, text="여기까지")
label_e.pack()
var_e = IntVar()
var_e.set(first_page)
entry_e = Entry(root, textvariable=var_e, validate='key')
entry_e['validatecommand'] = (entry_e.register(validate), '%P', '%d')
entry_e.pack()
entry_e.focus_set()
def callback():
global first_page
first_page = int(entry_f.get())
parser(int(entry_e.get()), True, True)
root.destroy()
btn = Button(root, text="확인", width=10, command=callback)
btn.pack()
root.mainloop()
# wa-event parser
def parser(max_pages=1, multiple=False, log=False):
# initialize first page no.
if type(max_pages) != int:
exit()
if multiple:
page = first_page - 1
else:
page = max_pages - 1
# save output
if log:
sys.stdout = open('output.txt', 'w')
while page < max_pages:
page += 1
url = base_url + str(page)
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text, 'lxml')
# skip if event was expired
if soup.string:
if soup.string.find('종료된 이벤트'):
continue
# Page No. & Title parsing
for title in soup.select('li.tit > strong'):
print('Page No. ' + str(page) + '<br>')
print('Title: ' + title.string + '<br>')
print('URL: ' + url + '<br>')
# Image parsing (<img> tag)
for link in soup.select('li.evt_ctt img'):
print('<img src="' + link['src'] + '">')
# Image parsing (<style> tag)
if soup.style:
string = soup.style.string
print('<img src="' + string[string.find('background:url(')+len('background:url('):string.find('.jpg)')+len('.jpg')] + '">')
print('<br>')
if __name__ == "__main__":
dialog()
@blood72
Copy link
Author

blood72 commented May 30, 2021

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment