Answer the question
In order to leave comments, you need to log in
Parser error in python. IndexError: list index out of range. how to fix?
import requests
from bs4 import BeautifulSoup as BS
import telebot
zodiacs = {"Козерог": {"unicode": 9809, "latin": "Capricon"} }
def get_horoscope(zodiac, URL='https://horoscopes.rambler.ru'):
ASKURL = f'{URL}/{zodiac.lower()}/'
HEADERS = {
'User-Agent': 'Mozilla/5.0 (Windows NT 6.0; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0'}
response = requests.get(ASKURL, headers=HEADERS)
soup = BS(response.content, 'html.parser')
item = soup.findAll('div', class_='_1E4Zo _3BLIa')[0]
parse_result = item.find('p', class_='mtZOt').get_text(strip=True)
return parse_result
def get_info(zodiac):
ask_horo = zodiacs[zodiac].get('latin')
uni_horo = chr(zodiacs[zodiac].get('unicode'))
result_horo = get_horoscope(ask_horo)
return f'Результаты для знака зодиака {zodiac}- {ask_horo} - {uni_horo}\n{result_horo}'
my_horo = get_info('Козерог')
print(my_horo)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question