{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8f7ee9ed",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-fd19a00f47ad1a34",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "- [Beautiful Soup Documentation](https://beautiful-soup-4.readthedocs.io/en/latest/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "ebaad76f",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-9138585fc343d8a7",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "from bs4 import BeautifulSoup"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1336423a",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-235041934d89cb33",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "source": [
    "## Example of Parsing a Website"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8bf54e3b",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-c6761d82e17018f0",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "with open(\"example.html\") as html_file:\n",
    "    soup = BeautifulSoup(html_file)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "14566e25",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-93b2d5726c5469a8",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<title>Test HTML</title>\n",
      "Test HTML\n",
      "------------------------------\n",
      "Print all list elements on the website:\n",
      "Item 1\n",
      "\n",
      "Item 2\n",
      "\n",
      "              Item 3\n",
      "          \n"
     ]
    }
   ],
   "source": [
    "print(soup.title)\n",
    "print(soup.title.get_text())\n",
    "\n",
    "\n",
    "print(\"-\"*30)\n",
    "print(\"Print all list elements on the website:\")\n",
    "\n",
    "li = soup.find_all(\"li\")\n",
    "for element in li:\n",
    "    print(element.get_text()) # you can use .strip() to get rid of trailing whitespace"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "d64b13b5",
   "metadata": {
    "nbgrader": {
     "grade": false,
     "grade_id": "cell-3a99db5db1577717",
     "locked": true,
     "schema_version": 3,
     "solution": false,
     "task": false
    }
   },
   "outputs": [],
   "source": [
    "import requests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4bdf24a4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "celltoolbar": "Create Assignment",
  "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.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
