Skip to content

Instantly share code, notes, and snippets.

@kyujin-cho
Last active December 8, 2020 08:06
Show Gist options
  • Save kyujin-cho/b9a4c82a7551f0fd80f1de76e98de922 to your computer and use it in GitHub Desktop.
Save kyujin-cho/b9a4c82a7551f0fd80f1de76e98de922 to your computer and use it in GitHub Desktop.
import requests
from bs4 import BeautifulSoup as BSoup
import xml.etree.ElementTree as ET
import time
import urllib.parse
import re
print('FMCleaner by 故술레이만')
time.sleep(0.1)
print('Licensed by GPLv3')
time.sleep(0.1)
print('소스코드는 쪽지주세요')
time.sleep(0.1)
print('ID와 PW를 ID PW 순으로 입력하세요 (예: ID가 foo, PW가 bar면 `foo bar` 이렇게)')
base_text = '''<?xml version="1.0" encoding="utf-8" ?>
<methodCall>
<params>
<_filter><![CDATA[delete_document]]></_filter>
<mid><![CDATA[{}]]></mid>
<document_srl><![CDATA[{}]]></document_srl>
<module><![CDATA[board]]></module>
<act><![CDATA[procBoardDeleteDocument]]></act>
</params>
</methodCall>'''
reply_base_text = 'document_srl={}&mid=&comment_srl={}&module=board&act=procBoardDeleteComment'
# mid에는 게시판명, document_srl에는 게시글 ID
username, password = input().split(' ')[:2]
with requests.Session() as s:
data = {
'module': 'member',
'act': 'procMemberLogin',
'redirect_url': 'http://www.fmkorea.com',
'user_id': username.strip(),
'password': password.strip()
}
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Host': 'www.fmkorea.com',
'Referer': 'http://www.fmkorea.com',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0'
}
login = s.post('https://www.fmkorea.com', data=urllib.parse.urlencode(data), headers=headers)
soup = BSoup(login.text, 'html.parser')
print(data)
if soup.find('div', {'class': 'logged_info'}).find('span', {'class': 'li2'}).text == '회원 가입':
print('로그인 실패')
exit()
posts = s.get('http://www.fmkorea.com/index.php?mid=home&act=dispMemberOwnDocument')
soup = BSoup(posts.text, 'html.parser')
page_count = int(soup.find('a', {'class': 'nextEnd'})['href'].split('=')[-1])
pages = [soup]
print('총 게시글', page_count, '페이지 확인')
posts = s.get('http://www.fmkorea.com/index.php?mid=home&act=dispMy_commentViewMyComment')
soup = BSoup(posts.text, 'html.parser')
reply_page_count = int(soup.find('a', {'class': 'nextEnd'})['href'].split('=')[-1])
reply_pages = [soup]
print('총 댓글', reply_page_count, '페이지 확인')
print(1, '페이지 불러오는 중...')
for i in range(2, page_count + 1):
print(i, '페이지 불러오는 중...')
url = 'http://www.fmkorea.com/index.php?mid=home&act=dispMemberOwnDocument&page=' + str(i)
posts = s.get(url)
pages.append(BSoup(posts.text, 'html.parser'))
print(1, '페이지 불러오는 중...')
for i in range(2, reply_page_count + 1):
print(i, '페이지 불러오는 중...')
url = 'http://www.fmkorea.com/index.php?mid=home&act=dispMy_commentViewMyComment&page=' + str(i)
posts = s.get(url)
reply_pages.append(BSoup(posts.text, 'html.parser'))
for page in pages:
documents = page.find('div', {'class': 'content_dummy'}).find('table').find('tbody').find_all('tr')
for document in documents:
try:
doc_board = document.find('td', {'class': 'nowrap'}).text.strip()
doc_mid = document.find('td', {'class': 'nowrap'}).find('a')['href'].split('/')[-1]
doc_id = document.find('td', {'class': 'w100'}).find('a')['href'].split('/')[-1]
title = document.find('td', {'class': 'w100'}).find('a').text.strip()
if doc_board == '-':
continue
print('{} ({}) 게시판의 '.format(doc_board, doc_mid), end='')
print('{} 번 게시글({}) 을 찾았습니다.'.format(doc_id, title))
url = 'https://www.fmkorea.com/write.php'
data = base_text.format(doc_mid, doc_id)
headers = {
'Host': 'www.fmkorea.com',
'X-Requested-With':'XMLHttpRequest',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0',
'Content-Type':'text/plain',
'Referer':'https://www.fmkorea.com/index.php?document_srl={}&mid=football_world&act=dispBoardDelete'.format(doc_id)
}
res = s.post(url, data=data, headers=headers)
print(res.text)
xml_root = ET.fromstring(res.text)
xml_message = xml_root.find('message').text
print('결과:', res.status_code, end=' ')
print('서버로부터의 메세지:', xml_message)
time.sleep(0.2)
except Exception as e:
print(e)
for page in reply_pages:
documents = page.find('div', {'class': 'content_dummy'}).find('table').find('tbody').find_all('tr')
for document in documents:
try:
doc_board = document.find('td', {'class': 'nowrap'}).text.strip()
doc_mid = document.find('td', {'class': 'nowrap'}).find('a')['href'].split('/')[-1]
params = document.find('td', {'class': 'w100'}).find('a')['href'].split('/')[-1].split('?')[-1]
reply = document.find('td', {'class': 'w100'}).find('a').text.strip()
params = urllib.parse.parse_qs(params)
reply_id = params['s_comment_srl'][0].split('#')[0]
doc_id = params['document_srl'][0]
if doc_board == '-' or '삭제된 댓글입니다' in reply:
continue
print('{} ({}) 게시판의 '.format(doc_board, doc_mid), end='')
print('{}#{} 번 댓글({}) 을 찾았습니다.'.format(doc_id, reply_id, reply))
url = 'https://www.fmkorea.com/write.php'
data = reply_base_text.format(doc_id, reply_id)
headers = {
'X-Requested-With':'XMLHttpRequest',
'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0',
'Content-Type':'application/json',
'Host': 'www.fmkorea.com',
'Referer':'https://www.fmkorea.com/index.php?document_srl={}&s_comment_srl={}'.format(doc_id, reply_id)
}
print(data)
print(headers)
res = s.post(url, data=data, headers=headers)
print('결과: {}, 서버로부터의 메세지: {}'.format(res.status_code, res.text))
time.sleep(0.2)
except Exception as e:
print(e)
@SanKim7
Copy link

SanKim7 commented Dec 8, 2020

지금도 사용가능한가요?

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