May-19-2020, 12:44 AM
Good Afternoon!
I have been following a tutorial on beautiful soup by Corey Schafer, but I came across an error when writing the code, and I do not know how I can debug it, considering the code is the same as it is in the video. Could this be due to how old/outdated the information on the video could be? and is there a way to debug this program? Thank you!
I have been following a tutorial on beautiful soup by Corey Schafer, but I came across an error when writing the code, and I do not know how I can debug it, considering the code is the same as it is in the video. Could this be due to how old/outdated the information on the video could be? and is there a way to debug this program? Thank you!
from bs4 import BeautifulSoup import requests with open('simple.html') as html_file: soup = BeautifulSoup(html_file, 'lxml') for article in soup.find('div', class_='footer'): headline = (article.h2.a.text) print(headline) summary = (article.p.text) print(summary) print()
Error:Traceback (most recent call last):
File "/Users/name/Desktop/untitled folder 2/covidscraper.py", line 8, in <module>
headline = (article.h2.a.text)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/bs4/element.py", line 885, in __getattr__
self.__class__.__name__, attr))
AttributeError: 'NavigableString' object has no attribute 'h2'