The dataset is currently empty. Upload or create new data files. Then, you will be able to explore them in the Dataset Viewer.
YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
!pip install requests-html import requests from bs4 import BeautifulSoup import csv
Function to scrape data from the website
def scrape_website(url): # Send a GET request to the URL response = requests.get(url)
# Check if the request was successful
if response.status_code == 200:
# Parse the HTML content
soup = BeautifulSoup(response.content, 'html.parser')
# Find the press release content
press_release_content = soup.find('div', {'id': 'divPressRelease'})
# Extract the title and content
title = press_release_content.find('h1').text.strip()
content = press_release_content.find('div', {'class': 'pressreldetail'}).text.strip()
return title, content
else:
print("Failed to retrieve data from the website.")
return None, None
Main function
def main(): # URL of the website to scrape url = 'https://www.pib.gov.in/PressReleasePage.aspx?PRID=1895315'
# Scrape data from the website
title, content = scrape_website(url)
# Write the scraped data to a CSV file
if title and content:
with open('scraped_data.csv', 'w', newline='', encoding='utf-8') as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['Title', 'Content'])
writer.writerow([title, content])
print("Scraped data has been saved to 'scraped_data.csv'.")
else:
print("No data was scraped.")
- Downloads last month
- 5