Created
July 20, 2021 12:39
-
-
Save editionc18/337d0fbfbe5e3ef629117b0d9542f360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 사용 전 터미널에 다음 명령어를 입력해 주세요: | |
# pip3 install bs4 requests | |
from bs4 import BeautifulSoup as bs | |
import requests as req | |
import time | |
login_info = {'user_id': '여기에_ID_입력', 'password': '여기에_비밀번호_입력'} | |
# 상수 | |
LOGIN_URL = 'https://meeco.kr/index.php?mid=index&act=dispMemberLoginForm' | |
MY_DOC_URL = 'https://meeco.kr/index.php?act=dispMemberOwnDocument' | |
BASE_URL = 'https://meeco.kr' | |
MENUS = {'소식': 'news', '미니기기': 'mini', '음향': 'Sound', '리뷰': 'Review', '대형': 'big', | |
'자유': 'free', '유머': 'humor', '갤러리': 'gallery', '익명': 'anonymous', '특가': 'Price', '장터': 'market', | |
'신고/건의': 'contact', '분쟁': 'Dispute'} | |
# 함수 | |
# 작성글 1페이지의 URL을 긁어오는 함수. | |
# 추가: MID도 필요해서 추가. | |
def get_doc_list(page): | |
parsed_doc = bs(page.text, 'html.parser') | |
doc = parsed_doc.select( | |
'section.cCon table.m-table > tbody td.title > a') | |
menu = parsed_doc.select( | |
'section.cCon table.m-table > tbody td.w_browser > a') | |
menu_list = [i['data'] for i in menu] | |
doc_list = [i['href'][1:] for i in doc] | |
mid_list = [None for i in range(len(doc_list))] | |
for i in range(len(menu_list)): | |
for j in MENUS.keys(): | |
if j in menu_list[i]: | |
mid_list[i] = MENUS[j] | |
break | |
doc_and_mid = {doc_list[i]: mid_list[i] for i in range(len(mid_list))} | |
return doc_and_mid | |
with req.session() as s: | |
# 로그인 과정 | |
csrf_token = bs(s.get(LOGIN_URL).text, 'html.parser').find( | |
'meta', {'name': "csrf-token"})['content'] | |
login_info = {**login_info, **{ | |
'error_return_url': '/index.php?mid=index&act=dispMemberLoginForm', | |
'mid': 'index', | |
'vid': '', | |
'ruleset': '@login', | |
'success_return_url': 'https://meeco.kr/', | |
'act': 'procMemberLogin', | |
'xe_validator_id': 'modules/member/skin/default/login_form/1', | |
'keep_signed': 'Y', | |
'_rx_csrf_token': csrf_token, | |
}} | |
login = s.post(LOGIN_URL, data=login_info, headers={ | |
'X-CSRF-Token': csrf_token}) | |
# 글 지우기~~~~ | |
while get_doc_list(s.get(MY_DOC_URL)) != {}: | |
doc_and_mid = get_doc_list(s.get(MY_DOC_URL)) | |
for i in doc_and_mid.keys(): | |
req = s.post(BASE_URL, data={'_filter': 'delete_document', | |
'error_return_url': '/index.php?mid=' + doc_and_mid[i] + '&document_srl=' + i + '&act=dispBoardDelete', | |
'act': 'procBoardDeleteDocument', | |
'mid': doc_and_mid[i], | |
'page': '1', | |
'document_srl': i, | |
'module': 'board', '_rx_ajax_compat': 'XMLRPC', '_rx_csrf_token': csrf_token}, | |
headers={'X-CSRF-Token': csrf_token, 'x-requested-with': 'XMLHttpRequest'}) | |
print(req.status_code) | |
time.sleep(3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment