Answer the question
In order to leave comments, you need to log in
Why doesn't the text appear?
Here is the code, the problem is that it doesn't want to show the text, why?
import requests
from bs4 import BeautifulSoup
url = requests.get('http://almetpt.ru/2020/site/schedule/group/835')
print(url.status_code)
soup = BeautifulSoup(url.text, "html.parser")
allNews = soup.findAll('div', class_='container')
print(allNews.text)
Traceback (most recent call last):
File "D:/programmer/PyCharm Community Edition 2020.2.3/bot_parser.py", line 10, in <module>
print(allNews.text)
File "D:\programmer\PyCharm Community Edition 2020.2.3\venv\lib\site-packages\bs4\element.py", line 2253, in __getattr__
raise AttributeError(
AttributeError: ResultSet object has no attribute 'text'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?
Answer the question
In order to leave comments, you need to log in
findall() output text with a loop
import requests
from bs4 import BeautifulSoup
url = requests.get('http://almetpt.ru/2020/site/schedule/group/835')
print(url.status_code)
soup = BeautifulSoup(url.text, "html.parser")
allNews = soup.findAll('div', class_='container')
# цикл
for text_all in allNews:
print(text_all.text)
import requests
from bs4 import BeautifulSoup
url = requests.get('http://almetpt.ru/2020/site/schedule/group/835')
print(url.status_code)
soup = BeautifulSoup(url.text, "html.parser")
allNews = soup.findAll('div', class_='container')
print(allNews[0].text)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question