VOOZH about

URL: https://www.geeksforgeeks.org/python/how-to-extract-script-and-css-files-from-web-pages-in-python/

⇱ How to Extract Script and CSS Files from Web Pages in Python ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Extract Script and CSS Files from Web Pages in Python ?

Last Updated : 23 Jul, 2025

Prerequisite:

In this article, we will discuss how to extract Script and CSS Files from Web Pages using Python.

For this, we will be downloading the CSS and JavaScript files that were attached to the source code of the website during its coding process. Firstly, the URL of the website needed to be scraped is determined and a request is sent to it. After retrieving Websites' content two folders for two file types are created and the files are placed into them and then we can perform various operations on them according to our need.

Module Needed

  • bs4: Beautiful Soup(bs4) is a Python library for pulling data out of HTML and XML files. This module does not come in built-in with Python.
  • requests:  Requests allow you to send HTTP/1.1 requests extremely easily. This module also does not come in built-in with Python.

Example 1: 

Here we are counting the number of fetched links for each respective type.

Output:

Total 7 javascript files found

Total 14 CSS files found

We can also use file handling to import fetched links into the text files.

Example 2:

Comment