The Python code I provided specifically uses the BeautifulSoup library to parse the HTML. You can see it in these lines:
python
from bs4 import BeautifulSoup # This line imports the library
# ...
soup = BeautifulSoup(response.body, 'html.parser') # This line uses it
video_items = video_container.find_all('div', class_='thumb-block') # And so does this
Because the code depends on it, you must install it. You can do this with pip:
bash
pip install beautifulsoup4
I also recommend installing a faster parser like lxml for BeautifulSoup to use under the hood. If it's available, BeautifulSoup will automatically use it, making your script run faster.
bash
pip install lxml
For Requests: No, not for the code I provided.
This is a great point of clarification. I mentioned Requests in the "Tools needed" section because it's a standard, almost essential tool for general web scraping in Python.
However, the Scrapy framework has its own powerful, built-in system for handling HTTP requests (scrapy.Request). The code I wrote relies entirely on Scrapy's system. You can see this here:
python
# This is Scrapy's way of making a new request
yield scrapy.Request(next_page_url, callback=self.parse)
Notice we never import requests in the script. Therefore, for this specific project, Scrapy handles all the networking, so you don't need to install the requests library separately.
Summary & Corrected Installation
To run the script I provided, you only need to install Scrapy and BeautifulSoup.
Here is a single command to install everything you need:
bash
pip install scrapy beautifulsoup4 lxml
My apologies for the confusion by including Requests in the initial list. It's a fantastic library, but redundant when you're working inside the Scrapy framework.