-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdown2-8-2.py
More file actions
38 lines (28 loc) · 1.06 KB
/
down2-8-2.py
File metadata and controls
38 lines (28 loc) · 1.06 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
from bs4 import BeautifulSoup
import urllib.request as req
import urllib.parse as rep
import os
import sys
import io
sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')
savePath ="C:\\imagedown\\"
base = "https://www.inflearn.com/"
quote = rep.quote_plus("추천-강좌")
url = base + quote
res = req.urlopen(url).read()
soup = BeautifulSoup(res,"html.parser")
recommand = soup.select("ul.slides")[0]
try:
if not(os.path.isdir(savePath)):
os.makedirs(os.path.join(savePath))
except OSError as e:
if e.errno != errno.EEXIST:
print("Failed to create directory!!!!!")
raise
for i,e in enumerate(recommand,1):
with open(savePath+"title_"+str(i)+".txt", "wt") as f:
f.write(e.select_one("h4.block_title > a ").string)
fullfilename = os.path.join(savePath, savePath+'img_'+str(i)+'.png')
req.urlretrieve(e.select_one("div.block_media > a > img")['src'],fullfilename)
print("강좌 정보 텍스트 출력 및 이미지 다운 완료!")