forked from OIDC-JT/Function
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrawling_json.py
51 lines (38 loc) · 2.31 KB
/
crawling_json.py
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
import re
from urllib.request import urlopen
from bs4 import BeautifulSoup
import json
def NBP(lst):
html = urlopen("https://www.ncloud.com/charge/region/ko")
bs = BeautifulSoup(html, "html.parser")
index = 1
List = [] #크롤링한 정보
for child in bs.find("tbody").children:
#a1 = str(child).replace('Standard-g2','').replace('High CPU-g2','').replace('High Memory-g2','').replace('<tr><th rowspan="5">', '').replace('<td rowspan="5">일반 데이터베이스 서버<br/>개인 홈페이지 운영</td>','').replace('<td rowspan="5">과학적 모델링<br/>게임 서버</td>','').replace('<td rowspan="5">고성능 데이터베이스 서버<br/>대규모 게임 서비스</td>','').replace('<tr><td>','').replace('</td></tr>','').replace(',','').replace('</td><td>', ', ').replace('</th><td>','').replace('원','W')
a1 = str(child).replace('Standard-g2','').replace('High CPU-g2','').replace('High Memory-g2','').replace('</td><td data-v-978526a4="" rowspan="5">일반 데이터베이스 서버<br data-v-978526a4=""/>개인 홈페이지 운영','').replace('</td><td data-v-978526a4="" rowspan="5">과학적 모델링<br data-v-978526a4=""/>게임 서버','').replace('</td><td data-v-978526a4="" rowspan="5">고성능 데이터베이스 서버<br data-v-978526a4=""/>대규모 게임 서비스','').replace('</td></tr>','').replace(',','').replace('원','W').replace('<tr data-v-978526a4=""><th data-v-978526a4="" rowspan="5"></th><td data-v-978526a4="">','').replace('<tr data-v-978526a4=""><td data-v-978526a4="">','').replace('</td><td data-v-978526a4="">',',')
a2 = a1.split(',')
if index < 6:
a2.insert(0, 'Standard-g2')
a2.insert(0, index)
elif index < 11:
a2.insert(0, 'High CPU-g2')
a2.insert(0, index)
elif index < 16:
a2.insert(0, 'High Memory-g2')
a2.insert(0, index)
elif index == 16:
break
item_obj = {
'ID' : index,
'Name' : a2[1],
'CPU' : a2[2],
'MEM' : a2[3],
'Disk' : a2[4],
'MPrice' : a2[5],
'YPrice' : a2[6],
}
List.append(item_obj)
index += 1
Li = {'server' : List}
a3 = json.dumps(Li, indent = 7)
return a3