https://ntp.msn.com/edge/ntp?locale=ja
Microsoft Edge ↑ I took the news from this URL and tried to display it, but an error occurred to see if BeautifulSoup was working properly.
import requests
from bs4 import BeautifulSoup
load_url="https://ntp.msn.com/edge/ntp?locale=ja"
html=requests.get(load_url)
soup = BeautifulSoup(html.content, "html.parser")
print(soup)
topic=soup.find(class_="news-list")
for element intopic.find_all("a"):
print(element.text)
This code
topic=soup.find(class_="news-list")
An exception has occurred: AttributeError
'NoneType' object has no attribute 'find_all'
File "Hidden Path", line 10, in <module>
for element intopic.find_all("a"):
The error
occurs.
If anyone knows how to solve it, please reply.
You probably don't understand where the error occurred.
The question states that an error occurred on the following line:
topic=soup.find(class_="news-list")
The error message indicates that an error occurred on the following line:
for element intopic.find_all("a"):
Since it is actually If there is still a gap in perception around here, it is more likely that the investigation will never progress and will not be resolved by making mistakes in what or what needs to be investigated and addressed. Has it been confirmed that there is an element with the class name I think it would be better to work step by step so that you can gradually move from those prerequisites to the program.'NoneType' object has no attribute 'find_all'
, and the object topic
is NoneType
(=None), the first problem is presented because it does not have the attribute find_all
(in this case, method) _group>.
"news-list"
in the web page contents that can be retrieved manually by using the MS-Edge browser instead of the Python program?
609 GDB gets version error when attempting to debug with the Presense SDK (IDE)
578 Understanding How to Configure Google API Key
910 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
571 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.