Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:text': 0.04; 'from:addr:yahoo.co.uk': 0.05; "subject:' ": 0.07; 'subject:code': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Getting': 0.09; 'subject:Why': 0.09; 'advance': 0.10; 'output': 0.13; 'subject: \n ': 0.15; 'programmers,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rejects': 0.16; 'soup': 0.16; 'subject:Started': 0.16; 'wrote:': 0.16; 'string': 0.17; 'attribute': 0.18; 'subject:page': 0.18; 'input': 0.18; 'language': 0.19; 'meant': 0.22; 'lawrence': 0.22; 'parsing': 0.22; 'text,': 0.22; 'file.': 0.22; 'help.': 0.23; 'seems': 0.23; 'words': 0.24; 'header:In-Reply-To:1': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; 'header:X-Complaints- To:1': 0.26; 'pertinent': 0.29; 'skip:b 40': 0.29; 'code': 0.30; 'skip:s 30': 0.31; 'language.': 0.32; "skip:' 20": 0.34; 'file': 0.34; 'handle': 0.34; 'advice': 0.35; 'done': 0.35; 'text.': 0.35; 'but': 0.36; 'should': 0.36; 'lines': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'thank': 0.38; 'sure': 0.39; 'does': 0.39; 'skip:- 60': 0.39; 'takes': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'subject:with': 0.40; 'your': 0.60; 'address': 0.61; 'documents': 0.61; 'charset:windows-1252': 0.62; 'our': 0.64; 'beautiful': 0.66; 'dear': 0.67; 'console,': 0.84; 'construct': 0.84; 'pythonistas,': 0.84; 'received:2': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Why doesn't input code return 'plants' as in 'Getting Started with Beautiful Soup' text (on page 30) ? Date: Sun, 12 Jul 2015 00:06:46 +0100 References: Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: host-2-98-199-67.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1436656022 news.xs4all.nl 2870 [2001:888:2000:d::a6]:35501 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:93708 On 11/07/2015 23:17, Simon Evans wrote: > Dear Programmers, > Thank you for your advice regarding giving the console a current address in the code for it to access the html file. > > The console seems to accept the code to that extent, but when I input the two lines of code intended to access the location of a required word, the console rejects it re : > > AttributeError:'NoneType' object has no attribute 'li' > > However the document 'EcologicalPyramid.html' does contain the words 'li' and 'ul', in its text. I am not sure as to how the input is arranged to output 'plants' which is also in the documents text, but that is the word the code is meant to elicit. > > I enclose the pertinent code as input and output from the console, and the html code for the document 'EcologicalPyramid.html' > > Thank you in advance for your help. > > --------------------------------------------------------------------- >>>> with open("C:\Beautiful Soup\ecologicalpyramid.html","r") as ecological_pyramid: > soup = BeautifulSoup("C:\Beautiful Soup\ecological_pyramid.html","lxml") Beautiful Soup takes a string or a file handle so as it's good practise to use the "with open" construct this should do it:- soup = BeautifulSoup(ecological_pyramid,"lxml") but do you actually need the "lxml", with the simple parsing I've done in the past I've never used it? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence