국가 정보 취득 및 리스트화
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
import os
import requests
from bs4 import BeautifulSoup
os.system("clear")
url = "https://www.iban.com/currency-codes"
res = requests.get(url)
tbody = BeautifulSoup(res.text, "html.parser").find("tbody").find_all("td")
num = 0
db = []
print('Hello! Please choose select a country by number:')
for i in range(0,len(tbody),4):
if tbody[i+2].get_text() != '':
country = tbody[i].get_text().capitalize()
code = tbody[i+2].get_text()
item = [
country,
code
]
print(f'# {num} {country}')
num += 1
db.append(item)
def search():
try:
select = int(input('#: '))
if select <= len(db) -1:
print('You Chose', db[select][0])
print('The currency code is', db[select][1])
else:
print('Choose a number from the list.')
search()
except:
print('That wasn`t number.')
search()
search()
메모
- 국가 정보를 가져와 리스트 형식으로 출력