Aviaition School

Beautiful Soup is packaged as Python 2 code. When you install it for use with Python 3, it ʼs automatically converted to Python 3 code. If you don ʼt install the package, the code won ʼt be converted. There have also been reports on Windows machines of the wrong version being installed. If you get the ImportError “No module named HTMLParser”, your problem is that you ʼre running the Python 2 version of the code under Python 3. If you get the ImportError “No module named html.parser”, your problem is that you ʼre running the Python 3 version of the code under Python 2. In both cases, your best bet is to completely remove the Beautiful Soup installation from your system (including any directory created when you unzipped the tarball) and try the installation again. If you get the SyntaxError “Invalid syntax” on the line ROOT_TAG_NAME = u'[document]' , you need to convert the Python 2 code to Python 3. You can do this either by installing the package: $ python3 setup.py install or by manually running Python ʼs 2to3 conversion script on the bs4 directory: $ 2to3-3.2 -w bs4 Installing a parser Beautiful Soup supports the HTML parser included in Python ʼs standard library, but it also supports a number of third-party Python parsers. One is the lxml parser. Depending on your setup, you might install lxml with one of these commands: $ apt-get install python-lxml $ easy_install lxml $ pip install lxml If you ʼre using Python 2, another alternative is the pure-Python html5lib parser, which parses HTML the way a web browser does. Depending on your setup, you might install html5lib with one of these commands:
1 comment

Featured Articles

Aviaition School

Category:Commercial Aircraft Tyres

Beautiful Soup is packaged as Python 2 code. When you install it for use with Python 3, it ʼs automatically converted to Python 3 code. If you don ʼt install the package, the code won ʼt be converted. There have also been reports on Windows machines of the wrong version being installed. If you get the ImportError “No module named HTMLParser”, your problem is that you ʼre running the Python 2 version of the code under Python 3. If you get the ImportError “No module named html.parser”, your problem is that you ʼre running the Python 3 version of the code under Python 2. In both cases, your best bet is to completely remove the Beautiful Soup installation from your system (including any directory created when you unzipped the tarball) and try the installation again. If you get the SyntaxError “Invalid syntax” on the line ROOT_TAG_NAME = u'[document]' , you need to convert the Python 2 code to Python 3. You can do this either by installing the package: $ python3 setup.py install or by manually running Python ʼs 2to3 conversion script on the bs4 directory: $ 2to3-3.2 -w bs4 Installing a parser Beautiful Soup supports the HTML parser included in Python ʼs standard library, but it also supports a number of third-party Python parsers. One is the lxml parser. Depending on your setup, you might install lxml with one of these commands: $ apt-get install python-lxml $ easy_install lxml $ pip install lxml If you ʼre using Python 2, another alternative is the pure-Python html5lib parser, which parses HTML the way a web browser does. Depending on your setup, you might install html5lib with one of these commands:

1 comment

×