diff options
author | filip <“filip.rabiega@gmail.com”> | 2025-04-26 13:01:53 +0200 |
---|---|---|
committer | filip <“filip.rabiega@gmail.com”> | 2025-04-26 13:01:53 +0200 |
commit | cdbef4e091c9dfbbc7c93cdfc8205be30141b2a0 (patch) | |
tree | 6fc6e758ab9484a80d4007f27b4755dcc1fd8122 /chadscraper.py | |
parent | 1313d6aa9b8f69388e7d42ed32e7aca8c34ac35d (diff) | |
download | chadscraper-cdbef4e091c9dfbbc7c93cdfc8205be30141b2a0.tar.gz chadscraper-cdbef4e091c9dfbbc7c93cdfc8205be30141b2a0.tar.bz2 chadscraper-cdbef4e091c9dfbbc7c93cdfc8205be30141b2a0.zip |
added chadcrawler.py & chadscraper.py
Diffstat (limited to 'chadscraper.py')
-rw-r--r-- | chadscraper.py | 29 |
1 files changed, 29 insertions, 0 deletions
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') |