From cdbef4e091c9dfbbc7c93cdfc8205be30141b2a0 Mon Sep 17 00:00:00 2001 From: filip <“filip.rabiega@gmail.com”> Date: Sat, 26 Apr 2025 13:01:53 +0200 Subject: added chadcrawler.py & chadscraper.py --- chadscraper.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 chadscraper.py (limited to 'chadscraper.py') diff --git a/chadscraper.py b/chadscraper.py new file mode 100644 index 0000000..79e5ab6 --- /dev/null +++ b/chadscraper.py @@ -0,0 +1,29 @@ +import requests +from bs4 import BeautifulSoup +import csv + +def scrape_website(url, csv_filename): + # Send GET request + response = requests.get(url) + response.raise_for_status() + + # Parse the webpage + soup = BeautifulSoup(response.text, 'html.parser') + + # Extract relevant data (modify according to target site) + data = [] + for item in soup.find_all('div', class_='some-class'): # Change 'some-class' accordingly + title = item.find('h2').text.strip() + description = item.find('p').text.strip() + data.append([title, description]) + + # Save data to CSV + with open(csv_filename, 'w', newline='', encoding='utf-8') as file: + writer = csv.writer(file) + writer.writerow(['Title', 'Description']) # Header row + writer.writerows(data) + + print(f"Data saved to {csv_filename}") + +# Example usage +scrape_website('https://example.com', 'scraped_data.csv') -- cgit v1.2.3