{}
See how a CS professor is using our compiler for class assignment.
Try Programiz PRO for Educators!
Learn DSA with step-by-step code visualization.
Try Programiz PRO for Educators!
run-icon
main.py
# Online Python compiler (interpreter) to run Python online. # Write Python 3 code in this online editor and run it. import requests from bs4 import BeautifulSoup import pandas as pd import json def scrape_bu_facts(url='http://www.bu.edu/president/boston-university-facts-stats/'): response = requests.get(url) soup = BeautifulSoup(response.text, 'html.parser') facts = {} for li in soup.select('.facts li'): text = li.get_text(strip=True) if ':' in text: key, value = text.split(':', 1) facts[key.strip()] = value.strip() with open('bu_facts.json', 'w') as f: json.dump(facts, f, indent=2) print("✅ Saved: bu_facts.json") def scrape_uci_datasets(url='https://archive.ics.uci.edu/ml/datasets.php'): try: tables = pd.read_html(url) datasets = tables[0] # first table is usually the main one datasets.to_json('uci_datasets.json', orient='records', indent=2) print("✅ Saved: uci_datasets.json") except Exception as e: print("❌ UCI scraping failed:", e) def scrape_us_presidents(url='https://en.wikipedia.org/wiki/List_of_presidents_of_the_United_States'): try: tables = pd.read_html(url) presidents = tables[0] # Simplify multi-level headers if needed presidents.columns = [col if not isinstance(col, tuple) else col[-1] for col in presidents.columns] presidents.to_json('us_presidents.json', orient='records', indent=2) print("✅ Saved: us_presidents.json") except Exception as e: print("❌ Presidents scraping failed:", e) def main(): print("🔍 Scraping BU facts...") scrape_bu_facts() print("🔍 Scraping UCI datasets...") scrape_uci_datasets() print("🔍 Scraping U.S. Presidents list...") scrape_us_presidents() if __name__ == '__main__': main()
Output