import sys
import io
from bs4 import BeautifulSoup
import requests
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stddrr = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
# 로그인 유저정보
LOGIN_info = {
'user_id' : 'test_id_1234',
'user_pw' : 'test_pw_1234!'
}
# Session 생성 with 구문 안에서 유지
with requests.Session() as s:
login_req = s.post('https://user.ruliweb.com/member/login', data=LOGIN_info)
#html 소스 확인
print('login_req', login_req.text)
#header 확인
print('headers', login_req.headers)
if login_req.status_code == 200 and login_req.ok:
post_one = s.get('https://bbs.ruliweb.com/market/board/32/read/4851846?') # 게시글 가져와서 보기
post_one.raise_for_status()
soup = BeautifulSoup(post_one.text, 'html.parser')
article = soup.select_one('table:nth-of-type(3)').find_all('p')
for i in article:
if i.string is not None:
#DB INSERT, 엑셀 저장, 텍스트 가공
print(i.string)