Bioinformatics Black Maternal Health Scripts
# ==========================================
# Interactive Web Table Finder and Extractor
# ==========================================
# Author: Tavia English (BioinfoBMH)
# Date: October 2025
# Description:
# 1. Prompts user for a web URL
# 2. Saves the webpage as an HTML file
# 3. Extracts all tables using pandas
# 4. Shows preview of each table, asks for confirmation
# 5. Saves the selected table as CSV
# ==========================================
# Data is the most important part of data analysis. It is vital to have the highest level of integrity when collecting and analyzing data.
#The website used for this code is: https://www.childhealthdata.org/browse/compare-state-data-through-comparison-tables/archive/title-v-national-performance-measures-nsch-2020-2021
#Step 1 Import libraries and input web address
import requests
import pandas as pd
from bs4 import BeautifulSoup
# This program requires the user to locate reputable data and provide the website address.
# Ask user for the web address
url = input("Enter the full website address (starting with https://): ").strip()
# Step 2. Download and save the HTML page
response = requests.get(url)
if response.status_code == 200:
with open("downloaded_page.html", "w", encoding="utf-8") as file:
file.write(response.text)
print("✅ Page successfully saved as 'downloaded_page.html'")
else:
print(f"❌ Failed to retrieve the page. Status code: {response.status_code}")
exit()
# Step 3. Extract tables using pandas
try:
tables = pd.read_html("downloaded_page.html")
except ValueError:
print("❌ No tables were found on the page.")
exit()
print(f"✅ Found {len(tables)} table(s) on the page.\n")
# Step 4. Loop through each table and show a preview
selected_table = None
for idx, table in enumerate(tables):
print("="*80)
print(f"🔍 Table {idx + 1} preview:")
print(table.head(10)) # show first 10 rows
print("="*80)
user_input = input("Is this the correct table? (y/n/skip/quit): ").strip().lower()
if user_input in ['y', 'yes']:
selected_table = table
print(f"✅ Table {idx + 1} selected.")
break
elif user_input in ['q', 'quit']:
print("🛑 Exiting without saving any table.")
exit()
else:
print("➡️ Skipping to next table...\n")
# Step 5. Save the chosen table
if selected_table is not None:
output_name = input("Enter a name for your output file (without extension): ").strip()
selected_table.to_csv(f"{output_name}.csv", index=False)
print(f"✅ Table saved as '{output_name}.csv'")
else:
print("⚠️ No table was selected.")
Bridgewater Joy Residence
Co-designed by the world-renowned architect James Smith, our Bridgewater Joy residences offer top views of the nearby lake Michigan. Perfect for a small family, a professional couple, or anyone looking to set up a home office.
Pleasantview Gem Inn
Not just pleasant on the outside, our Pleasantview Gem Inn properties are especially popular among families. With underground parking and floor-to-ceiling windows, there's no shortage of natural light or space.