Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Michael Poehner
4,714 Points'NoneType' object is not subscriptable
'NoneType' object is not subscriptable I am not sure why this is throwing an error in Python web scraping
from urllib.request import urlopen from bs4 import BeautifulSoup
import re
def internal_links(linkURL): html = urlopen('https://treehouse-projects.github.io/horse-land/{}' .format(linkURL)) soup = BeautifulSoup(html, 'html.parser')
return soup.find('a', href=re.compile('(.html)$'))
if name == 'main': urls =internal_links('index.html') while len(urls) > 0: page = urls.attr['href']
print(page)
print('\n===============\n')
urls = internal_links(page)
1 Answer
Michael Poehner
4,714 PointsI am sorry I just figured it out. I put urls.attr instead of urls.attrs.
Mark Chesney
11,747 PointsMark Chesney
11,747 PointsI have an additional question: so is
hrefbelow just akwargmade up in that line? Since href isn't normally a predefined parameter to theBeautifulSoup.find()method, I wonder if I understand that right, do I?return soup.find('a', href=re.compile('(.html)$'))