BeautifulSoup remove tags from html to get text

Source: Internet
Author: User

In [1]: from BS4 import BeautifulSoup

In [2]: s = "' <div class=" Markdown_views ">
...: <p>beautifulsoup is a library of Python, the main function is from the Web page
...: Crawl the data we need. BeautifulSoup parsing HTML into objects for processing, all page transitions
...: For a dictionary or an array, the relative hermetical of the expression means that the process can be greatly simplified. </p>
...:
...:


...:
...: <p> recommended install BeautifulSoup 4 version using PIP to install:</p> "

In [4]: bs = BeautifulSoup (S, "Html.parser")

In [5]: print (Bs.text)
---------------------------------------------------------------------------
Unicodeencodeerror Traceback (most recent)
<ipython-input-5-0ea5f8e54d3a> in <module> ()
----> 1 print (bs.text)

Unicodeencodeerror: ' ASCII ' codec can ' t encode character U ' \u662f ' in position 14:ordinal not in range (128)

in [+]: Import sys

in [+]: Reload (sys
...: )
<module ' sys ' (built-in) >

in [+]: sys.setdefaultencoding (' Utf-8 ')

in [+]: bs = BeautifulSoup (S, "Html.parser")

in [+]: print (Bs.text)

BeautifulSoup is a library of Python, and the main function is to crawl the data we need from the Web. BeautifulSoup parsing HTML into an object for processing, all pages into a dictionary or array, relative to the hermetical expression, can greatly simplify the process.
0X01 Installation
It is recommended to install the BeautifulSoup 4 version using PIP for installation:

In [20]:

BeautifulSoup remove tags from html to get text

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.