scrapy.py
unknown
python
2 years ago
845 B
3
Indexable
import requests import os # URL of the website you want to clone url = "https://www.example.com" # Directory where you want to save the downloaded files save_directory = "path/to/save-directory" # Create the save directory if it doesn't exist if not os.path.exists(save_directory): os.makedirs(save_directory) # Send a GET request to the website response = requests.get(url) # Retrieve the content type of the response content_type = response.headers['Content-Type'] # Extract the file extension from the content type file_extension = content_type.split("/")[-1] # Save the response content to a file file_path = os.path.join(save_directory, f"index.{file_extension}") with open(file_path, "wb") as file: file.write(response.content) # Print the file path where the file is saved print(f"File saved successfully to: {file_path}")
Editor is loading...