Answer the question
In order to leave comments, you need to log in
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'
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
I want to make a bot in a telegram for fun
I don't understand python very well.
title = post.find("a", class_="post__title_link").text.strip()
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 questionAsk a Question
731 491 924 answers to any question