L
L
LeoNetreba2020-06-10 17:25:31
Python
LeoNetreba, 2020-06-10 17:25:31

How do I fix an error in python IndexError: list index out of range?

I wrote a program with parsing, but it gives an error IndexError: list index out of range.

Here is the code:
import requests
from bs4 import BeautifulSoup as BS

URL = ' https://freecurrencyrates.com/en/convert- '
USD_UAH = 'USD-UAH'
USD_RUB = 'USD-RUB'

r = requests.get(URL)
soup = BS(r.content, 'html.parser')
items = soup.findAll('input', {'class': "thin", 'id': "value_to"})

input_text = input('Get the USD exchange rate in UAH or RUB: ')

if input_text.lower() == 'uah':
course = URL + USD_UAH
print('Now $1 is ' + items[0]['value'] + 'UAH'

print('Now $1 is ' + items[0]['value'] + 'UAH')

else:
print('ERROR')

This is how I did it at the beginning:
import requests
from bs4 import BeautifulSoup as BS

URL = ' https://freecurrencyrates.com/en/convert-USD-UAH '

r = requests.get(URL)
soup = BS(r.content, 'html.parser')
items = soup.findAll('input', {'class': "thin", 'id': "value_to"})

input_text = input('Find out USD to UAH rate yes or no: ')

if input_text.lower() == 'yes':
print(' Now $1 is ' + items[0]['value'] + 'UAH')

elif input_text.lower() == 'no':
print('Bye then')

else:
print('ERROR')

PLEASE HELP TO FIX IT!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Pokrovsky, 2020-06-10
@Makaroshka007

https://freecurrencyrates.com/en/convert-
Page not found, error 404

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question