Simon Evans wrote: > Dear Jussi, and Billy > I have changed the input in accordance with your advice, re: > ------------------------------------------------------------------------------ > Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] > on win 32 > Type "help", "copyright", "credits" or "license" for more information. >>>> from bs4 import BeautifulSoup >>>> with open("ecologicalpyramid.html","r") as ecological_pyramid: > ... soup = next(ecological_pyramid,"lxml") > ... producer_entries = soup.find("ul") > ... print(producer_entries.li.div.string) > ... print(producer_entries.li.div.string)
Simon, you are not leaving a blank space between the indented block and the unindented line. The interactive interpreter is quite simple, and you MUST leave a blank line after indented blocks. You need to press the ENTER key *twice* at the end of the block: with open("ecologicalpyramid.html","r") as ecological_pyramid: ENTER TAB soup = next(ecological_pyramid,"lxml") ENTER TAB producer_entries = soup.find("ul") ENTER TAB print(producer_entries.li.div.string) ENTER ENTER print(producer_entries.li.div.string) ENTER Don't type the letters E N T E R, press the ENTER key. The same goes for TAB. Note carefully that after the indented block, there is a blank line. It should look like this: >>> with open("ecologicalpyramid.html","r") as ecological_pyramid: ... soup = next(ecological_pyramid,"lxml") ... producer_entries = soup.find("ul") ... print(producer_entries.li.div.string) ... >>> print(producer_entries.li.div.string) If you don't leave the blank line, then *nothing* in that "with" block will run and consequently the last print line will fail. Until you fix that, we cannot even begin to help with any other issues you might be having. -- Steven -- https://mail.python.org/mailman/listinfo/python-list