6. Text Summarization and Text Generation
Activity 11: Summarizing a Downloaded Page Using the Gensim Text Summarizer
Solution
Let's summarize a downloaded page with the help of the Gensim text summarizer. Follow these steps to implement this activity:
- Open a Jupyter notebook.
- Insert a new cell and add the following code to import the necessary libraries:
import warnings warnings.filterwarnings('ignore') from gensim.summarization import summarize import requests
- The following code uses the
requests
library to get the Why Click page. After getting the page, we change the encoding toutf-8
in order to properly decode some of the content on the page. Then, we useBeautifulSoup
to find the text content of the div with the ID#why-click
. This div contains the main text of thewhy-click
page:from bs4 import BeautifulSoup r = requests.get('https://click.palletsprojects.com/en/7.x/why/') r.encoding = 'utf-8' soup = BeautifulSoup(r.text...