Path: csiph.com!usenet.pasdenom.info!gegeweb.org!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'from:addr:yahoo.co.uk': 0.04; 'output': 0.05; 'tree': 0.05; 'nicely': 0.07; 'parser': 0.07; 'urllib2': 0.07; '__init__': 0.09; 'lawrence': 0.09; 'library?': 0.09; 'output,': 0.09; 'parsers': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'setup.py': 0.09; 'valueerror:': 0.09; 'python': 0.11; 'language.': 0.14; 'newlines': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'requisite': 0.16; 'subject: \n ': 0.16; 'subject:accessing': 0.16; 'url:packtpub': 0.16; 'all.': 0.16; 'language': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'command': 0.22; 'input': 0.22; 'import': 0.22; 'install': 0.23; 'header :User-Agent:1': 0.23; 'builder': 0.24; 'skip:" 40': 0.26; 'subject:/': 0.26; 'header:X-Complaints-To:1': 0.27; 'header:In- Reply-To:1': 0.27; 'installed': 0.27; 'tried': 0.27; 'went': 0.31; 'code': 0.31; '"",': 0.31; '>>>>': 0.31; 'subject:these': 0.31; 'file': 0.32; 'text': 0.33; 'says': 0.33; '(most': 0.33; 'skip:b 30': 0.33; "i'd": 0.34; 'subject:from': 0.34; "can't": 0.35; 'skip:u 20': 0.35; 'something': 0.35; 'but': 0.35; 'should': 0.36; 'wrong': 0.37; 'being': 0.38; 'expected': 0.38; 'skip:o 20': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; "couldn't": 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'even': 0.60; 'above,': 0.60; 'subject: ': 0.61; 're:': 0.63; 'our': 0.64; 'more': 0.64; 'needing': 0.65; 'charset:windows-1252': 0.65; 'world': 0.66; 'due': 0.66; 'bottom': 0.67; 'beautiful': 0.68; 'detail.': 0.68; "'we": 0.84; 'received:2': 0.84; '2013,': 0.91; 'statutory': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Mark Lawrence Subject: Re: Installing Parsers/Tree Builders to, and accessing these packages from Python2.7 Date: Sun, 02 Nov 2014 22:31:48 +0000 References: <9580043d-a75b-4b87-9a21-1b9c0347671f@googlegroups.com> <75794999-f188-470a-96d1-3d8fca80cbf7@googlegroups.com> 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-204-224.as13285.net User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: <75794999-f188-470a-96d1-3d8fca80cbf7@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 88 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414967524 news.xs4all.nl 2896 [2001:888:2000:d::a6]:44387 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80145 On 02/11/2014 21:59, Simon Evans wrote: > > Oh I don't mind quoting console output, I just thought I'd be sparing you > > unnecessary detail. > > output was going nicely as I input text from my 'Getting Started with > > Beautiful Soup' even when the author reckoned things would go wrong - due to > > lxml not being installed, things went right, because I had already installed > > it, re: > ---------------------------------------------------------------------------- > page 17 > ---------------------------------------------------------------------------- > 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. >>>> import urllib2 >>>> from bs4 import BeautifulSoup >>>> url = "http://www.packtpub.com/books" >>>> page = urllib2.urlopen(url) >>>> soup_packtpage = BeautifulSoup(page) >>>> with open("foo.html","r") as foo_file: > ... soup_foo = Soup(foo_file) > File "", line 2 > soup_foo = Soup(foo_file) > ^ > IndentationError: expected an indented block >>>> soup_foo= BeautifulSoup("foo.html") > ---------------------------------------------------------------------------- > page 18 > ---------------------------------------------------------------------------- >>>> print(soup_foo) >

foo.html

>>>> soup_url = BeautifulSoup("http://www.packtpub.com/books") >>>> print(soup_url) >

http://www.packtpub.com/books

>>>> helloworld = "

Hello World

" >>>> soup_string = BeautifulSoup(helloworld) >>>> print(soup_string) >

Hello World

> ---------------------------------------------------------------------------- > page 19: no code in text on this page > ---------------------------------------------------------------------------- > page 20 > ---------------------------------------------------------------------------- >>>> soup_xml = BeautifulSoup(helloworld,features= "xml") >>>> soup_xml = BeautifulSoup(helloworld,"xml") >>>> print(soup_xml) > >

Hello World

>>>> soup_xml = BeautifulSoup(helloworld,features = "xml") >>>> print(soup_xml) > >

Hello World

>>>> > ---------------------------------------------------------------------------- > Then on bottom of page 20 it says 'we should install the required parsers using easy-install,pip or setup.py install' but as I can't get the downloads of html or html5 parsers, text code halfway down returns statutory response regarding requisite parser needing to be installed, re: > ---------------------------------------------------------------------------- > page 21 > ---------------------------------------------------------------------------- >>>> invalid_html = '>>> soup_invalid_html = BeautifulSoup(invalid_html,'lxml') >>>> print(soup_invalid_html) > >>>> soup_invalid_html = BeautifulSoup(invalid_html,'html5lib') > Traceback (most recent call last): > File "", line 1, in > File "C:\Python27\lib\site-packages\bs4\__init__.py", line 155, in __init__ > % ",".join(features)) > ValueError: Couldn't find a tree builder with the features you requested: html5lib. Do you need to install a parser library? >>>> Have you tried this from the command prompt? pip install html5lib And please do something about the extra newlines and single lined paragraphs above, there's no need for it all. -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence