Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #93726
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2015-07-12 01:59 -0700 |
| References | <cbcc6d3f-1fc7-4caf-b6d9-3a7ff9d8f1d5@googlegroups.com> |
| Message-ID | <f0b23331-69f6-4503-b9f5-52024fb78609@googlegroups.com> (permalink) |
| Subject | Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? |
| From | Simon Evans <musicalhacksaw@yahoo.co.uk> |
Dear Mark Lawrence, thank you for your advice.
I take it that I use the input you suggest for the line :
soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid.html",lxml")
seeing as I have to give the file's full address I therefore have to modify your :
soup = BeautifulSoup(ecological_pyramid,"lxml")
to :
soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid," "lxml")
otherwise I get :
>>> with open("C:\Beautiful Soup\ecologicalpyramid.html"."r")as ecological_pyramid:
>>> soup = BeautifulSoup(ecological_pyramid,"lxml")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'ecological_pyramid' is not defined
so anyway with the input therefore as:
>>> with open("C:\Beautiful Soup\ecologicalpyramid.html"."r")as ecological_pyramid:
>>> soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid,","lxml")
>>> producer_entries = soup.find("ul")
>>> print(producer_entries.li.div.string)
I still get the following output from the console:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'NoneType' object has no attribute 'li'
>>>
As is probably evident, what is the problem Python has with finding the required html code within the 'ecologicalpyramid' html file, or more specifically why does it respond that the html file has no such attribute as 'li' ?
Incidentally I have installed all the xml, lxml, html, and html5 TreeBuilders/ Parsers. I am using lxml as that is the format specified in the text.
I may as well quote the text on the page in question in 'Getting Started with Beautiful Soup':
'Since producers come as the first entry for the <ul>tag, we can use the find() method, which normally searches fo ronly the first occurrance of a particular tag in a BeautifulSoup object. We store this in producer_entries. The next line prints the name of the first producer. From the previous HTML diagram we can understand that the first producer is stored inside the first <div> tag of the first <li> tag that immediately follows the first <ul> tag , as shown inthe following code:
<ul id = "producers">
<li class= "producerlist">
<div class= "name">plants</div>
<div class="name">100000</div>
</li>
</ul>
So after running the preceding code, we will get plants, which is the first producer, as the output.'
(page 30)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Simon Evans <musicalhacksaw@yahoo.co.uk> - 2015-07-11 15:17 -0700
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-12 00:06 +0100
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Simon Evans <musicalhacksaw@yahoo.co.uk> - 2015-07-12 01:59 -0700
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Peter Otten <__peter__@web.de> - 2015-07-12 11:51 +0200
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Simon Evans <musicalhacksaw@yahoo.co.uk> - 2015-07-12 04:48 -0700
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Peter Otten <__peter__@web.de> - 2015-07-12 14:26 +0200
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Simon Evans <musicalhacksaw@yahoo.co.uk> - 2015-07-12 05:36 -0700
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Simon Evans <musicalhacksaw@yahoo.co.uk> - 2015-07-12 05:48 -0700
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Peter Otten <__peter__@web.de> - 2015-07-12 15:12 +0200
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Larry Hudson <orgnut@yahoo.com> - 2015-07-12 13:06 -0700
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Simon Evans <musicalhacksaw@yahoo.co.uk> - 2015-07-12 10:33 -0700
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? MRAB <python@mrabarnett.plus.com> - 2015-07-12 19:05 +0100
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-12 19:23 +0100
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? "Albert Visser" <albert.visser@gmail.com> - 2015-07-12 20:34 +0200
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Laura Creighton <lac@openend.se> - 2015-07-12 21:47 +0200
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-12 21:09 +0100
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Laura Creighton <lac@openend.se> - 2015-07-12 22:29 +0200
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-07-12 21:48 +0100
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Laurent Pointal <laurent.pointal@free.fr> - 2015-07-12 19:54 +0200
Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Chris Angelico <rosuav@gmail.com> - 2015-07-13 03:58 +1000
csiph-web