Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ?

Simon Evans musicalhacksaw at yahoo.co.uk
Sun Jul 12 08:36:31 EDT 2015


Dear Peter Otten,
Incidentally, you have discovered a fault in that there is an erroneous difference in my code of 'ecologicalpyramid.html' and that given in the text, in the first few lines re: 
----------------------------------------------------------------------------
<html> 
<body> 
<div class="ecopyramid"> 
<ul id= "producers"> 
<li class="producers"> 
<li class="producerlist"> 
<div class="name">plants</div> 
<div class="number">100000</div> 
</li> 
<li class="producerlist"> 
<div class="name">algae</div> 
<div class="number">100000</div> 
</li> 
</ul> 
----------------------------------------------------------------------------
<html>
<body>
<div class="ecopyramid">
<ul id= "producers">
<li class="producerlist">
<div class="name">plants</div>
<div class="number">100000</div>
</li>
<li class="producerlist">
<div class="name">algae</div>
<div class="number">100000</div>
</li>
</ul>
----------------------------------------------------------------------------
I have removed the line <li class="producers"> to the right html code of the lower 

version. Now there is a string ("plants") between the <"li class producerlist"> and </li>
Sorry about that.
However as you said, the input code as quoted in the text, still won't return 'plants' 

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
>>> soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid,","lxml")
>>> producer_entries = soup.find("ul")
>>> print(producer_entries.li.div.string)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'li'
>>> 
----------------------------------------------------------------------------



More information about the Python-list mailing list