D
D
DenDuatlov2021-06-11 23:43:16
Python
DenDuatlov, 2021-06-11 23:43:16

Parser error in python. What's wrong?

I apologize in advance for the stupid question, but I could not find a solution and come to it yourself. After starting the parser, an error occurs and the text (which was planned) is not displayed. The error code changes constantly, in this case it is . parser code below.
#This Python file uses the following encoding: utf-8
#Console.OutputEncoding = Encoding.UTF8

import requests
from bs4 import BeautifulSoup as BS

def parseras():
URL = ' '
HEADERS = {
'User-Agent': ''

}

response = requests.get(URL, headers=HEADERS)
soup = BS(response.content, 'html.parser')
items = soup.findAll('div', class_ ='
comps = []
for item in items:
comps.append({
'title': item.find('p', class_='mtZOt').get_text(strip = True)
})
for comp in comps:
print(comp[ 'title'])


parseras()
print(parseras)

trying to hook it up to the telegram bot only writes this error, not the text.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-06-12
@DenDuatlov

Business, over morning coffee, comb the rest yourself:

import requests
from bs4 import BeautifulSoup as BS


zodiacs = {
    "Овен": {"unicode": 9800, "latin": "Aries"},
    "Телец": {"unicode": 9801, "latin": "Taurus"},
    "Близнецы": {"unicode": 9802, "latin": "Gemini"},
    "Рак": {"unicode": 9803, "latin": "Cancer"},
    "Лев": {"unicode": 9804, "latin": "Leo"},
    "Дева": {"unicode": 9805, "latin": "Virgo"},
    "Весы": {"unicode": 9806, "latin": "Libra"},
    "Скорпион": {"unicode": 9807, "latin": "Scorpio"},
    "Змееносец": {"unicode": 9934, "latin": "Ophiuchus"},
    "Стрелец": {"unicode": 9808, "latin": "Sagittarius"},
    "Козерог": {"unicode": 9809, "latin": "Capricon"},
    "Водолей": {"unicode": 9810, "latin": "Aquarius"},
    "Рыбы": {"unicode": 9811, "latin": "Pisces"}
}


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)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question