Python Forum

Full Version: Traceback error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Good morning / afternoon. I am working on a activity where I am supposed to get siblings from a teaching website. I am getting a traceback error and I don't understand it. I have tried everything I can think of.

Here is the code I'm trying to run. Notice at the top - I have 4 rows rather than the two my activity shows. Yesterday, I learned that using this will help with dealing with errors so I've chosen to use these in all the code I create. The two rows my activity calls for is "import urlopen" and "from bs4 import BeautifulSoup". I have tried removing my additions but it didn't resolve the error.

from urllib.request import urlopen
from urllib.error import HTTPError
from urllib.error import URLError
from bs4 import BeautifulSoup

html = urlopen('http://www.pythonscraping.com/pages/page3.html')
bs = BeautifulSoup(html, 'html.parser')

for sibling in bs.find('table', {'id':'giftList'}).tr.nest_siblings:
    print(sibling)
This is the error I get.

Error:
== RESTART: C:\Python365\Web Scraping with Python\Dealing with siblings.py == Traceback (most recent call last): File "C:\Python365\Web Scraping with Python\Dealing with siblings.py", line 9, in <module> for sibling in bs.find('table', {'id':'giftList'}).tr.nest_siblings: TypeError: 'NoneType' object is not iterable >>>
I will most appreciate any help you provide!
Well without diving to deeply I would start by trying to figure out which variable is of type None. Essentially, the error is telling you that there is a variable that you are attempting to iterate that is of type None on line 9.
it is next_siblings
I think at the moment it looks for a tag nest_siblings
buran - that was it exactly! I need to look closer at what I'm typing!

Thank you!