-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMHN_REPORT.py
More file actions
63 lines (44 loc) · 1.54 KB
/
MHN_REPORT.py
File metadata and controls
63 lines (44 loc) · 1.54 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
#오늘부터 N일까지의 기사를 가져오는 프로그램
import requests
from bs4 import BeautifulSoup
from datetime import date, timedelta
url = 'https://www.mhns.co.kr/member/login.php' # 로그인 endpoint
data = {
'user_id': 'entrkjm',
'user_pw': '!1qaz@2wsx'
}
s = requests.Session()
resp = s.post(url, data=data)
# 여기서 S 객체에 다시 한번 GET을 사용
my_page = 'http://www.mhns.co.kr/news/userWriterArticleList.html'
resp = s.get(my_page)
soup = BeautifulSoup(resp.text, features='lxml')
dates = []
n = int(input('오늘부터 며칠 내의 기사를 가져올까요?: '))
for i in range(n):
dates.append(str(date.today()+timedelta(days=i)))
table_row = list(soup.select('.table-row'))
list_tag = []
for i in table_row:
test = i.select_one('.list-dated').get_text()
for j in range(n):
if test.find(dates[j]) != -1:
list_tag.append(i)
res = [[] for i in range(len(list_tag))]
for k in range(len(list_tag)):
res[k].append(list_tag[k].select_one('.list-section'))
res[k].append(list_tag[k].find('strong'))
print(res[k][0].get_text(), res[k][1].get_text())
# Dummy Test Codes:
# for j in list_tag:
# print(j.find('strong').get_text(), j.select('list-section').get_text())
# a_tag = list(soup.select('.links'))
# small_tag = list(soup.select('.list-section'))
# result1 = []
# result2 = []
# for i in a_tag:
# result2.append(i.find('strong').get_text())
# for j in small_tag:
# result1.append(j.get_text())
# for k in range(len(result1)):
# print(result1[k] + result2[k])