Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeLollo21 authored Aug 19, 2024
1 parent 023d729 commit 6577fb2
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions web_scraping.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": []
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "T759RY9e6IKS",
"outputId": "a0088064-2a49-4b47-b6a0-1827afc23bf8"
},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Requirement already satisfied: beautifulsoup4 in /usr/local/lib/python3.10/dist-packages (4.12.3)\n",
"Requirement already satisfied: soupsieve>1.2 in /usr/local/lib/python3.10/dist-packages (from beautifulsoup4) (2.6)\n",
"Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (2.32.3)\n",
"Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.10/dist-packages (from requests) (3.3.2)\n",
"Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests) (3.7)\n",
"Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests) (2.0.7)\n",
"Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests) (2024.7.4)\n"
]
}
],
"source": [
"!pip install beautifulsoup4\n",
"\n",
"!pip install requests"
]
},
{
"cell_type": "code",
"source": [
"import requests\n",
"\n",
"from bs4 import BeautifulSoup\n",
"\n",
"page = requests.get(\"https://quotes.toscrape.com/\")\n",
"html = page.content\n",
"soup = BeautifulSoup(html, 'html.parser')\n",
"\n",
"quotes = soup.findAll('span', attrs={'class':'text'})\n",
"authors = soup.findAll('small', attrs={\"class\":\"author\"})\n",
"\n",
"for quote, author in zip(quotes, authors):\n",
" print(quote.text + \"-\" + author.text)"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "ToxHlxX86sg-",
"outputId": "b8c8660b-f5e7-4181-f70f-c498d7130138"
},
"execution_count": 15,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"“The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”-Albert Einstein\n",
"“It is our choices, Harry, that show what we truly are, far more than our abilities.”-J.K. Rowling\n",
"“There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”-Albert Einstein\n",
"“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”-Jane Austen\n",
"“Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.”-Marilyn Monroe\n",
"“Try not to become a man of success. Rather become a man of value.”-Albert Einstein\n",
"“It is better to be hated for what you are than to be loved for what you are not.”-André Gide\n",
"“I have not failed. I've just found 10,000 ways that won't work.”-Thomas A. Edison\n",
"“A woman is like a tea bag; you never know how strong it is until it's in hot water.”-Eleanor Roosevelt\n",
"“A day without sunshine is like, you know, night.”-Steve Martin\n"
]
}
]
},
{
"cell_type": "code",
"source": [
"import csv\n",
"file = open('scraped_quotes.csv', 'w')\n",
"writer = csv.writer(file)\n",
"writer.writerow(['Quote', 'Author'])\n",
"\n",
"for quote, author in zip(quotes, authors):\n",
" print(quote.text + \"-\" + author.text)\n",
" writer.writerow([quote.text, author.text])\n",
"file.close()"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "CfspiEuF7voT",
"outputId": "476be9f4-0ffa-4744-cf8c-87a6cb44edae"
},
"execution_count": 16,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"“The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”-Albert Einstein\n",
"“It is our choices, Harry, that show what we truly are, far more than our abilities.”-J.K. Rowling\n",
"“There are only two ways to live your life. One is as though nothing is a miracle. The other is as though everything is a miracle.”-Albert Einstein\n",
"“The person, be it gentleman or lady, who has not pleasure in a good novel, must be intolerably stupid.”-Jane Austen\n",
"“Imperfection is beauty, madness is genius and it's better to be absolutely ridiculous than absolutely boring.”-Marilyn Monroe\n",
"“Try not to become a man of success. Rather become a man of value.”-Albert Einstein\n",
"“It is better to be hated for what you are than to be loved for what you are not.”-André Gide\n",
"“I have not failed. I've just found 10,000 ways that won't work.”-Thomas A. Edison\n",
"“A woman is like a tea bag; you never know how strong it is until it's in hot water.”-Eleanor Roosevelt\n",
"“A day without sunshine is like, you know, night.”-Steve Martin\n"
]
}
]
}
]
}

0 comments on commit 6577fb2

Please sign in to comment.