동적 크롤링이 좋은데 동적 시간안에 못해서 정적 

어제 함수를 좀 응용해서 불러왔다 파일 임포트 참조~

import os
import requests
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

from bs4 import BeautifulSoup
from babel.numbers import format_currency
from day5 import play5

os.system("clear")



def comefileday5():
  biglist = play5.firstwork()
  return biglist

def finding(biglist):  
  country = input("#: ")
  if country.isdecimal():
    number = int(country)
    if number <= len(biglist):
      print(biglist[number][1])
      return number
    else:
      print("Choose a number from the list.")
      return finding(biglist)
  else:
    print("That wasn\'t a number.")
    return finding(biglist)

def money(papper1,papper2):  
  print(f"\nHow many {papper1} do you want to convert to {papper2}?")
  moneyback = input()
  if moneyback.isdecimal():
    number = int(moneyback)
    return number
  else:
    print("That wasn\'t a number.")
    return money(papper1,papper2)

  

def extractmoney(money1, money2, mymoney):
  result = requests.get(f"https://transferwise.com/gb/currency-converter/{money1}-to-{money2}-rate?amount={mymoney}")
  soup = BeautifulSoup(result.text,"html.parser")
  change = soup.find_all('input',{"id":"rate"})
  
  listdata = []

  for form in change:
    listdata.append(form)
  listsimple=str(listdata[0]).split()
  for i in listsimple:
    if 'value' == i[0:5]:
      moneychange = float(i[7:-3])
      done = float(mymoney)*moneychange
      print(format_currency(float(mymoney), money1.upper(), locale="ko_KR"),end= '')
      print(' is ',end='')
      print(format_currency(done, money2.upper(), locale="ko_KR"))

  



def startgame():  
  print("Welcome to CurrencyConvert PRO 2000")
  biglist = comefileday5()
  print("\nWhere are you from? Choose a country by number.\n")
  country_num1 = biglist[finding(biglist)][3]
  print("\nNow choose another country.\n")
  country_num2 = biglist[finding(biglist)][3]
  mymoneyback = money(country_num1.upper(),country_num2.upper())
  extractmoney(country_num1.lower(),country_num2.lower(),mymoneyback)


"""
Use the 'format_currency' function to format the output of the conversion
format_currency(AMOUNT, CURRENCY_CODE, locale="ko_KR" (no need to change this one))


print(format_currency(5000, "KRW", locale="ko_KR"))
"""

 

다음첼린지할때 이쁘게 해야징~

블로그 이미지

Or71nH

,

정적 크롤링 하기~!

import requests
from bs4 import BeautifulSoup


def finding(biglist):
    country = input("#: ")
    if country.isdecimal():
        number = int(country)
        if number <= len(biglist):
            print("You chose", biglist[number][1])
            print("The currency code is", biglist[number][3].upper())
        else:
            print("Choose a number from the list.")
            return finding()
    else:
        print("That wasn\'t a number.")
        return finding()


def findurlcode():
    indeed_result = requests.get('https://www.iban.com/currency-codes')
    indeed_soup = BeautifulSoup(indeed_result.text, "html.parser")
    datalist = indeed_soup.find(
        "table", {"class": "table table-bordered downloads tablesorter"})
    pages = datalist.find_all('tr')
    biglist = []
    count = 0
    for i in pages[1:]:
        minilist = []
        minilist.append(count)
        for k in i:
            if k != "\n":
                data = str(k.string)
                if data.isdecimal():
                    minilist.append(int(data))
                else:
                    minilist.append(data[0] + data[1:].lower())
        if type(minilist[4]) == type(0):
            biglist.append(minilist)
            count += 1
    return biglist


def firstwork():
    biglist = findurlcode()
    for i in biglist:
        print("#", i[0], i[1])
    return biglist


def startgame():
    print("Hello! Please choose select a country by number:")
    biglist = firstwork()
    finding(biglist)

 

 

내일꺼랑 연관있어 함수 정리 잘해놓기~

 

블로그 이미지

Or71nH

,

퀴즈 

1. 스플릿 하기

2.url 만들기

3.url 검사

단!!! com 만되게 해놧다 
co.kr은 안됨!~!!
나중에 정규식 고쳐야한다~!

 

import requests
from bs4 import BeautifulSoup


def finding(biglist):
    country = input("#: ")
    if country.isdecimal():
        number = int(country)
        if number <= len(biglist):
            print("You chose", biglist[number][1])
            print("The currency code is", biglist[number][3].upper())
        else:
            print("Choose a number from the list.")
            return finding()
    else:
        print("That wasn\'t a number.")
        return finding()


def findurlcode():
    indeed_result = requests.get('https://www.iban.com/currency-codes')
    indeed_soup = BeautifulSoup(indeed_result.text, "html.parser")
    datalist = indeed_soup.find(
        "table", {"class": "table table-bordered downloads tablesorter"})
    pages = datalist.find_all('tr')
    biglist = []
    count = 0
    for i in pages[1:]:
        minilist = []
        minilist.append(count)
        for k in i:
            if k != "\n":
                data = str(k.string)
                if data.isdecimal():
                    minilist.append(int(data))
                else:
                    minilist.append(data[0] + data[1:].lower())
        if type(minilist[4]) == type(0):
            biglist.append(minilist)
            count += 1
    return biglist


def firstwork():
    biglist = findurlcode()
    for i in biglist:
        print("#", i[0], i[1])
    return biglist


def startgame():
    print("Hello! Please choose select a country by number:")
    biglist = firstwork()
    finding(biglist)
블로그 이미지

Or71nH

,

 

'''
Is Wed on 'days' list? True
The fourth item in 'days' is: Thu
['Mon', 'Tue', 'Wed', 'Thu','Fri', 'Sat', 'Sun', 'Sat']
['Tue', 'Wed', 'Thu', Fri', 'Sat', 'Sun', 'sat']
'''

'''
You need to create the following functions:
is_on_list
get_x
add_x
remove_x
'''


'''
DO NOT change anything inside of the "DO NOT TOUCH AREA"
해당 코드에서 빠진 함수가 있습니다. 위의 스크린과 같은 모습이 되도록 고쳐보세요.
반드시 위 표기된 함수들 (is_on_list. get_x. add_x. remove_x) 생성해야합니다.
DO NOT TOUCH 영역은 건들지마세요!
'''

퀴즈~~

"""
As you can see, the code is broken.
Create the missing functions, use default arguments.
Sometimes you have to use 'return' and sometimes you dont.
Start by creating the functions
"""

#^^^^^^^^^^^^^^^^^^^^^^^ Start ^^^^^^^^^^^^^^^^^^^^^^^^#
def is_on_list(inputlist, howdoUdo):
  if howdoUdo in inputlist:
    return True
  else:
    return False

def get_x(inputlist, howdoyoudo):
  return inputlist[howdoyoudo]

def add_x(inputlist, howUdo):
  return inputlist.append(howUdo)

def remove_x(inputlist, howyoudo):
  inputlist.remove(howyoudo)



# \/\/\/\/\/\/\  DO NOT TOUCH AREA  \/\/\/\/\/\/\ #

days = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

print("Is Wed on 'days' list?", is_on_list(days, "Wed"))

print("The fourth item in 'days' is:", get_x(days, 3))

add_x(days, "Sat")
print(days)

remove_x(days, "Mon")
print(days)


# /\/\/\/\/\/\/\ END DO NOT TOUCH AREA /\/\/\/\/\/\/\ #


 

이건 넘어가도록 하겟다~!

 

블로그 이미지

Or71nH

,

이런!! 틀렷다

 

첫날 가볍게 퀴즈 풀기~

 

블로그 이미지

Or71nH

,