{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "621c09fe", "metadata": {}, "outputs": [], "source": [ "from bs4 import BeautifulSoup\n", "import pandas as pd\n", "\n", "# Read HTML content from the file\n", "with open(\"index.html\", \"r\", encoding=\"utf-8\") as file:\n", " html_content = file.read()\n", "\n", "# Parse the HTML content\n", "soup = BeautifulSoup(html_content, \"html.parser\")\n", "\n", "# Find the table\n", "table = soup.find(\"table\")\n", "\n", "# Extract table data\n", "if table:\n", " rows = table.find_all(\"tr\")\n", " data = []\n", " for row in rows:\n", " columns = row.find_all(\"td\")\n", " if columns: # Ensure it's not a header row or empty row\n", " row_data = [column.text.strip() for column in columns]\n", " data.append(row_data)\n", " # Create DataFrame\n", " df = pd.DataFrame(data)\n", " \n", " # Extract first part and last word from the first column\n", " df['Name'] = df[0].str.split().str[:-1].str.join(\" \")\n", " df['Ticker'] = df[0].str.split().str[-1]\n", " df[['Name', 'Ticker']].to_csv(\"Company List.csv\")\n", "else:\n", " print(\"Table not found in the HTML content.\")\n" ] }, { "cell_type": "code", "execution_count": 1, "id": "38efd2c9", "metadata": {}, "outputs": [ { "ename": "NameError", "evalue": "name 'c' is not defined", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", "Cell \u001b[0;32mIn[1], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mc\u001b[49m)\n", "\u001b[0;31mNameError\u001b[0m: name 'c' is not defined" ] } ], "source": [ "print(c)" ] }, { "cell_type": "code", "execution_count": null, "id": "6c185203", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.13" } }, "nbformat": 4, "nbformat_minor": 5 }