Installation Beautiful soup

Beautiful Soup is a Python library can extract data from HTML or XML file. It enables document navigation through your favorite conventional converter, search, modify the way a document.

A. Installation Beautiful Soup

  • If you are using a new version of Debain or ubuntu, it can be installed by the package management system:$ apt-get install Python-bs4

  • Beautiful Soup 4 through PyPi release, so if you can not use the package management system installed, can also be installed via easy_install or pip. Package name is beautifulsoup4, this package is compatible with Python2 and Python3.
    $ easy_install beautifulsoup4
    $ pip install beautifulsoup4

    • (In PyPi there is a name BeautifulSoup bag, but probably not what you want, that is release version Beautiful Soup3, since many projects are still using BS3, so BeautifulSoup package is still valid. But if you're writing new project, then you should install beautifulsoup4)
  • If you have not installed easy_install or pip, you can also download the source code BS4, and then installed by setup.py.$ Python setup.py install

After the installation is complete

Beautiful Soup publishing packaged into Python2 version of the code, when installed in Python3 environment, will be automatically converted into Python3 code, if there is no installation process, the code will not be converted.

  • If the code throws an exception ImportError of: "No module named HTMLParser", because Python2 version of the code you execute Python3 version.

  • If the code throws an exception ImportError of: "No module named html.parser", because Python3 version of the code you execute Python2 version.

  • If you encounter the above two cases, the best solution is to reinstall BeautifulSoup4.

  • If '[document]' code is encountered at SyntaxError "Invalid syntax" error ROOT_TAG_NAME = u, Python code will need to release from BS4 to Python3 Python2 conversion can reinstall BS4:

    • $ Python3 setup.py install

    Or execute Python code conversion script version in bs4 directory

    • $ 2to3-3.2 -w bs4

How to use Beautiful soup

Published 51 original articles · won praise 29 · views 2389

Guess you like

Origin blog.csdn.net/fangweijiex/article/details/103736695