F
F
flexpc2022-03-30 21:17:14
Python
flexpc, 2022-03-30 21:17:14

Site parsing error?

Hello. For fun, I want to make a bot in a telegram that will send news from the school website. But when parsing, I get this error

Traceback (most recent call last):
  File "C:/Users/Andrew/PycharmProjects/SchoolBot/pars.py", line 11, in <module>
    title = post.find("a", class_="post__title_link").text.strip()
AttributeError: 'NoneType' object has no attribute 'text'

I don't understand python very well, so I'm asking for help. How can I solve this error?
import requests
from bs4 import BeautifulSoup

URL = "https://sch121uz.mskobr.ru/novosti"

page = requests.get(URL)
soup = BeautifulSoup(page.content, "html.parser")

post = soup.find("div", class_="kris-news-box")

title = post.find("a", class_="post__title_link").text.strip()
description = post.find("div", class_="post__text post__text-html post__text_v1").text.strip()
url = post.find("a", class_="post__title_link", href=True)["href"].strip()


print(title, description, url, sep="\n\n")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AVKor, 2022-03-30
@AVKor

I want to make a bot in a telegram for fun

I don't understand python very well.

One does not match the other at all.
title = post.find("a", class_="post__title_link").text.strip()

Since there are no links with the class on the page post__title_link, it takes the value . Hence the errorpost.find("a", class_="post__title_link")None
AttributeError: 'NoneType' object has no attribute 'text'
.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question