<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Nathanael Victorious on Medium]]></title>
        <description><![CDATA[Stories by Nathanael Victorious on Medium]]></description>
        <link>https://medium.com/@nathanaelvictorious?source=rss-b82c928aaf9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2MyzldoTAPPI16G7I29DTA.png</url>
            <title>Stories by Nathanael Victorious on Medium</title>
            <link>https://medium.com/@nathanaelvictorious?source=rss-b82c928aaf9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 05:55:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nathanaelvictorious/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Simple Web Scraping using BeautifulSoup and Python in Google Colab]]></title>
            <link>https://nathanaelvictorious.medium.com/simple-web-scraping-using-beautifulsoup-and-python-in-google-colab-4084be701851?source=rss-b82c928aaf9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4084be701851</guid>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[web-scraping]]></category>
            <dc:creator><![CDATA[Nathanael Victorious]]></dc:creator>
            <pubDate>Fri, 05 Feb 2021 12:13:09 GMT</pubDate>
            <atom:updated>2021-02-05T12:27:57.112Z</atom:updated>
            <content:encoded><![CDATA[<h4>Extracting data from a website and use it for analytics</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zI1H07fOlyexPd7B" /><figcaption>Photo by <a href="https://unsplash.com/@madmax_chef?utm_source=medium&amp;utm_medium=referral">MadMax Chef</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Hello everyone ! welcome to my first post ever on Medium. I’m currently taking Data Science path at <a href="http://codecademy.com/">Codecademy</a>, and just now I thought “Well, I want to write something about what I learned at Codecademy”, hence the post. Actually I have some topics that I want to write and post before, but I decided on this topic since I want to make Medium as a witness on my journey. Let’s begin !</p><h3>So why Web Scraping ?</h3><p>First thing first, let’s see the definition of Web Scraping from <a href="http://prowebscraper.com/">Prowebscraper.com</a> :</p><blockquote><a href="https://prowebscraper.com/blog/what-is-web-scraping/">Web scraping</a> is an automated way of extracting large chunks of data from websites which can then be saved on a file in your computer or accessed on a spreadsheet.</blockquote><p>So basically, Web Scraping is a method that let us to extract/acquire any data from any websites that available on the Internet.</p><h4>But why you do that ?</h4><p>Well in this 21st century now, <a href="https://www.forbes.com/sites/bernardmarr/2018/03/05/heres-why-data-is-not-the-new-oil/?sh=36c9c1043aa9">data</a> is everything. You can gain any information you needed from data ! You can do things like Machine Learning, Internet of Things Analytics, Business Analyst, and even <a href="https://www.analyticsvidhya.com/blog/2020/12/use-of-machine-learning-in-dairy-farming/">Predicting when your cow will produces milk</a> !.</p><p>With Web Scraping, you can gain data you need that can be used later for analytics. Let’s say you just start a new business in clothing industry, but as a newcomer you don’t really know what is the average price in the market right now, so how are you going to solve it ?. Yes the answer is Web Scraping ! You can use Web Scraping to look up the average price for your products. You can also scrape customer information, and find out how you can bring up their satisfaction by fine-tuning your market strategies.</p><p>Get the gist of it ? well without further ado, let’s jump to the main course !</p><h3>Importing necessary library</h3><pre>from bs4 import BeautifulSoup<br>import requests<br>import pandas as pd<br>import matplotlib.pyplot as plt<br>import numpy as np</pre><p>First thing we need to do is obviously to import the library needed, such as <a href="https://pypi.org/project/beautifulsoup4/">BeautifulSoup</a>, <a href="https://pypi.org/project/requests/">requests</a>, <a href="https://pypi.org/project/pandas/">pandas</a>, <a href="https://pypi.org/project/matplotlib/">matplotlib</a>, and <a href="https://pypi.org/project/numpy/">numpy</a>. (If you are using Visual Studio Code, PyCharm, Jupyter Notebook or etc. You can install the library first using pip command, click the link(s) for more guide !)</p><p>Each library served it’s own function, BeautifulSoup for.. well scraping website, requests for getting the URL, pandas for it’s powerful yet flexible data structure <em>DataFrame</em>, matplotlib for visualizing the data, and numpy for list computing &amp; analytics.</p><p>Now with all the library installed and imported, forward to the next step !</p><h3>Get the website &amp; extracting the data</h3><pre>webpage = requests.get(&quot;insert-your-url-here&quot;)</pre><pre>soup = BeautifulSoup(webpage.content, &quot;html.parser&quot;)</pre><p>The snippet above let us to save the URL into a <em>requests.models.Response </em>variable called “webpage” using the requests library, and then we use the BeautifulSoup to get the content of the website using html.parser into a variable called “soup”. By the way, I use Codecademy website as the source, it’s a simple website about Cocoa Ratings in the world. You can check the website <a href="https://content.codecademy.com/courses/beautifulsoup/cacao/index.html">here</a>.</p><h4>Understanding the structure of the website</h4><figure><img alt="Cocoa Ratings website from Codecademy used for Web Scraping in Data Science and Data Analytics" src="https://cdn-images-1.medium.com/max/1024/1*lTSVKy-ANGne1MeXlG89Ag.png" /><figcaption>Codecademy website about Cocoa Ratings</figcaption></figure><p>Before you jump in to the extraction, you must first understand the structure of the website you want to scrap by inspect the page. You can see the HTML by right clicking and choose inspect (or press CTRL + Shift + I) on the website page, then we will see the image below on our screen.</p><figure><img alt="HTML code from Inspect Element on Cocoa Ratings website for Web Scraping" src="https://cdn-images-1.medium.com/max/550/1*gzIYowvU0tsi3ZUF4l4JPA.png" /><figcaption>HTML Structure of Cocoa Ratings Website</figcaption></figure><p>If you having a hard time understanding the HTML structure you can learn the basic <a href="https://www.w3schools.com/html/html_intro.asp">here</a>.</p><p>In the image above you can see that every table data (&lt;td&gt;) in table row (&lt;tr&gt;) have their own classes, such as “Company”, “Origin”, “ReviewDate”, etc. From here I assume you already got the gist of the website component, obviously we are going to extract all the table data on &lt;tr&gt; and &lt;td&gt; element tags. See the code below for extracting data from the website</p><pre>example_column = soup.find_all(attrs={&quot;class&quot;: &quot;class-name&quot;})<br>example_list = []</pre><pre>for x in example_column[1:] : <br>   example_list.append(float(x.get_text()))</pre><p>Here we use the .find_all function on the soup variable that we declared before, this soup variable has the content of the website so we need to find what we need. In the code you can change the &quot;class&quot; to any HTML tags like &quot;id&quot; and &quot;class-name&quot; to any specific class/id name that you want to find.</p><p>Next you make an empty list example_list = [] for containing the content of the loop after this. I use <em>for</em> loops in this case so, for every x (data) in example_column[1:] <em>“Wait, why you add [1:] after the list name ?” </em>Yes it was intended, as you can see the table row is started from the column name (Company, Specific Bean Origin, REF, etc.)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JVnGU6NbTRPZ4gtPK8H6Vg.png" /></figure><p>and you don’t want your list to have the column name. Hence, we started from [1] (list indexing in Python starts from 0) and the colon after 1 means all the data from index 1 to n (n = the list size).</p><p>After the loop you want to insert every data on example_column to the example_list with the .append() function and float() is for changing the string value we got from x.get_text() to float.</p><p>Congratulations ! Now you can extract any data you want from any website using BeautifulSoup and Python. After all the long work extracting the data, here come the fun part, analyzing the data !</p><h3>Analyzing the data</h3><p>Okay now we arrive at the last part, first we need to see what is the data is telling us. We have 9 column, Company, Specific Bean Origin or Bar Name, REF, Review Date, Cocoa Percent, Company Location, Rating, Bean Type, and Broad Bean Origin.</p><p>Next we need to decide the question we want to ask, this time I want to find the correlation between Cocoa Percentage and Rating, after that I can make a prediction about how much Cocoa Percentage affect the Rating.</p><p>First we need to make the DataFrame using pandas to make things easier</p><pre>data = {&quot;Rating&quot;: ratings, &quot;CocoaPercentage&quot;: cocoa_percents}</pre><pre>df = pd.DataFrame.from_dict(data)</pre><p>ratings and cocoa_percents are lists that I extract from the website before, each lists contains rating column and cocoa percentage column.</p><p>After that we use the function from numpy library called .polyfit()</p><pre>z = np.polyfit(df.CocoaPercentage, df.Rating, 1)</pre><p>This function used in linear regression problems. Linear regression models the relationship between a dependent variable and an independent variable, obtaining a line that best fits the data. In this case the dependent variable is the <strong>Rating</strong> and the independent variable is the <strong>CocoaPercentage.</strong></p><p>Now we going to use .poly1d() functions from numpy (again) that helps to define a polynomial function from .polyfit().</p><pre>line_function = np.poly1d(z)</pre><p>And then we plot the result using matplotlib</p><pre>plt.scatter(df.CocoaPercentage, df.Rating)</pre><pre>plt.title(&#39;Cocoa Percentage &amp; Ratings Correlation&#39;)</pre><pre>plt.xlabel(&#39;Cocoa Percentage (%)&#39;)</pre><pre>plt.ylabel(&#39;Ratings&#39;)</pre><pre>plt.plot(df.CocoaPercentage, line_function(df.CocoaPercentage), &quot;r--&quot;)</pre><pre>plt.show()</pre><figure><img alt="Linear Regression Plot using Matplotlib on Python, Data Science" src="https://cdn-images-1.medium.com/max/386/1*Yw5aPhAgcQ6jFD5ruOXXig.png" /></figure><p>We can see based on the plot above that <strong>the higher the cocoa percentage then the ratings tend to be lower</strong>.</p><p>Here the whole code for this project</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1dc3bd4481b27b3a216d363692617960/href">https://medium.com/media/1dc3bd4481b27b3a216d363692617960/href</a></iframe><h3>The end</h3><p>That’s it for this article (or blog), thank you so much for reading my first article ! I’m sorry for any mistakes, grammatical errors, technical errors, typo, or even my explanation, please tell me what’s wrong in the comment or you can email me directly. See you on the next one ! ;)</p><blockquote>Don’t forget to leave a like and comment !</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4084be701851" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>