<?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 Kaus Pathak on Medium]]></title>
        <description><![CDATA[Stories by Kaus Pathak on Medium]]></description>
        <link>https://medium.com/@kaus.pathak_30409?source=rss-f5f76b51b980------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*48ic5ZDeslWb3L7-bihEhA.jpeg</url>
            <title>Stories by Kaus Pathak on Medium</title>
            <link>https://medium.com/@kaus.pathak_30409?source=rss-f5f76b51b980------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 01:57:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kaus.pathak_30409/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[Recreating the New York Times Covid-19 Spiral Graph]]></title>
            <link>https://medium.com/@kaus.pathak_30409/recreating-the-new-york-times-covid-19-spiral-graph-6306da2a4894?source=rss-f5f76b51b980------2</link>
            <guid isPermaLink="false">https://medium.com/p/6306da2a4894</guid>
            <category><![CDATA[covid-update]]></category>
            <category><![CDATA[spiral]]></category>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[covid19]]></category>
            <dc:creator><![CDATA[Kaus Pathak]]></dc:creator>
            <pubDate>Sat, 15 Jan 2022 00:00:00 GMT</pubDate>
            <atom:updated>2022-01-16T07:24:09.119Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7EDHQOj38iIQqeFZ" /><figcaption>Photo by <a href="https://unsplash.com/@edwinhooper?utm_source=medium&amp;utm_medium=referral">Edwin Hooper</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><a href="https://kaus98.github.io/2022/01/15/spiral-graph-python/">Recreating the New York Times Covid-19 Spiral Graph - Kaus Blog</a></p><p>Recently New York Times published an article with Spiral Graph representing the spread of Confirmed COVID-19 cases in US. The piece in question is titled <a href="https://www.nytimes.com/2022/01/06/opinion/omicron-covid-us.html">Here’s When We Expect Omicron to Peak.</a> The opener image, which attracted a lot of attention on Twitter, shows the number of new COVID cases in the U.S. since the beginning of 2020.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/0*_H8Ci-Vr9t6ppMNb.jpeg" /></figure><h3>Recreating the Graph with Python</h3><p>Despite the negative comments for spiral graphs to represent the data, i wanted to recreate the Graph, not in R like others but in python using only Matplotlib. I also wanted the option to add multiple countries in Spiral Graph for Comparison.</p><h3>Load and Preprocess the raw Data</h3><p>We use the COVID-19 Dataset by <a href="https://github.com/owid/covid-19-data">Our World in Data</a> for the number of confirmed Coronavirus cases all around the worlds. We will also add the options to plot other parameters including Smoothed Covid Cases, Deceased Cases and Positivity Rates.</p><p>To Download the Dataset, we can use Wget python Library or manually <a href="https://covid.ourworldindata.org/data/owid-covid-data.csv">download</a> and place the file in working directory.</p><pre>wget.download(‘https://covid.ourworldindata.org/data/owid-covid-data.csv&#39;, “data/Covid_Data.csv”)</pre><h3>Preprocessing the Data</h3><p>Since the original chart starts on January 1st, 2020, while the first cases for each country are presented on different dates, we add all the days from January 1st to the first date in the data. We also divided the Data for each country to different files based on ISO and placed in different files for ploting.</p><p>We also add the Extra Column of Days Passed since 2020–01–01 for Each Country. The day of the year will be our x-axis while the y-axis will denote the confirmed cases in country.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/11efaab4fb1b31af0867ecf9c92ea0cd/href">https://medium.com/media/11efaab4fb1b31af0867ecf9c92ea0cd/href</a></iframe><h3>Building Simple Spiral Graph</h3><p>We will start with building very simple Spiral graph in python which will act as base function for all the graphs. Some important features to note for this base class are:</p><ul><li>We will divide the spiral angles for each month based on number of days present in each month.</li><li>We will add the Y Ticks for starting of each year.</li><li>We will also add Watermark to add your name on bottom right.</li><li>Offset is added to not start the graph from zero. With code you can Change the Ancor with your name</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/00a23df1f6bc4b2cee8f78881209caa0/href">https://medium.com/media/00a23df1f6bc4b2cee8f78881209caa0/href</a></iframe><p>This will give us plain Spiral Graph without any Covid Markers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PfKBnlpSGx_znYwA.jpg" /></figure><p>Now we have plain spiral graph, we can start adding the markers of Covid new cases in any country. First we will add for US to check if we are getting similar graph as NY Times.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7778a918106d6c768a0a8e499bbb229b/href">https://medium.com/media/7778a918106d6c768a0a8e499bbb229b/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Bc0Yz8qpZD8rfGRsHKOU8A.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/615/1*n3FBTpz3YGUs0cwd0kJ_MQ.jpeg" /><figcaption>Our Image vs NYT Original Image</figcaption></figure><p>Now we will add other country which is India in our case and try to plot spiral graph.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DMf-yKhdrY1RjXkcc4sV0g.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*i9cVbP-Hc32FyD8m65eXbw.jpeg" /></figure><h4>Great. It Works.</h4><p>We can also create some other similar graphs that represent data in Spiral format but to much clear extend.</p><h3>Spiral with Single Bar Graph</h3><p>I have also added one other type of Graph inspired by <a href="https://twitter.com/soustha/status/1480595666036350976">souryashrestra</a> which follows lines instead of Fill.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xGyU1-kkyB_4eCstoDmjIg.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7x4Aep-pYMuvkmnMdp8fQQ.jpeg" /><figcaption>Spiral Graph for USA and India</figcaption></figure><h3>Spiral with Double Bar Graph</h3><p>Much like the previous Graph we can create double sided bar graph which can show 2 different countries stats at each of side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YPOrsB2TN-GDTarOM6j0DQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xFPpDHzYMCi1CX_OLXmNQw.jpeg" /></figure><h3>Double Sided Graph with Confirmed and Deceased Cases</h3><p>We can also represent 2 data on each side of Line representing New Confirmed and Deceased Cases for one Country.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C60ZIDHlLL8qBKMoitLxXQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6wwsO_-PgUjBJqBi_ZjwA.jpeg" /></figure><h3>Create the video from Graphs</h3><p>Since we have already create graph, we can create progression video with time. We can use ffmpeg default command to make Video from Images.</p><p>You can checkout sample Video from these Links.<br><a href="https://github.com/kaus98/spiral-graph-covid-nyc/blob/main/movie_india.mp4">Progression Video for India</a><br><a href="https://github.com/kaus98/spiral-graph-covid-nyc/blob/main/movie_usa.mp4">Progression Video for USA</a></p><p><em>Originally published at </em><a href="https://kaus98.github.io/2022/01/15/spiral-graph-python/"><em>https://kaus98.github.io</em></a><em> on January 15, 2022.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6306da2a4894" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner to Advance — Web Scraping Guide in Python: Deploy a Python Web App using Flask and…]]></title>
            <link>https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-deploy-a-python-web-app-using-flask-and-a0e3cc8ce9f6?source=rss-f5f76b51b980------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0e3cc8ce9f6</guid>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[heroku]]></category>
            <dc:creator><![CDATA[Kaus Pathak]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 14:06:04 GMT</pubDate>
            <atom:updated>2020-06-24T15:38:00.678Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Xf_mpLMpdOqNxaE5AelXow.png" /></figure><h3>Beginner to Advance — Web Scraping Guide in Python: Deploy a Python Web App using Flask and Postgres on Heroku.</h3><p>In Previous Tutorials , we learned about:</p><ul><li>Asyncio Programming</li><li>Rotating Requests with a pool of Headers and Proxies.</li><li>Web Scraping</li><li>RESTful API for lyrics using Flask and Postgresql.</li></ul><p>But in this final tutorial we will deploy the App using Heroku and test our API.</p><h3>About Heroku</h3><p><a href="https://www.heroku.com/">Heroku</a> is one of the first cloud platform as a service (PaaS) and supports several languages — Ruby, Java, Node.js, Scala, Clojure, Python, PHP, and Go.</p><p>The first thing we need to do is define which libraries our application uses. That way, Heroku knows which ones to provide for us, similar to how we install them locally when developing the app.</p><h4>Setup Heroku</h4><ul><li>Go to <a href="https://signup.heroku.com/">Heroku Signup</a> and create a free Account by verifying your Gmail Account.</li><li><a href="https://id.heroku.com/login">Log in</a> to your Account</li></ul><h4>System Setup</h4><ol><li>Firstly you need to install <a href="https://git-scm.com/downloads">Git</a> for your Os. Git allows and encourages you to have multiple local branches that can be entirely independent of each other.</li><li>Go to <a href="https://devcenter.heroku.com/articles/heroku-cli">this page</a> and install the Heroku CLI for your OS.</li><li>For Installing Heroku CLI on Ubuntu you can<a href="https://tecrobust.com/insall-heroku-platform-on-linux-ubuntu/"> follow these Steps</a>.</li><li>If installed correctly , You will be able to run command in Terminal:</li></ol><pre>git --version &amp;&amp; heroku --version</pre><h4>Gunicorn</h4><p>The Gunicorn “Green Unicorn” is a Python Web Server Gateway Interface HTTP server. It is a pre-fork worker model, ported from Ruby’s Unicorn project. The Gunicorn server is broadly compatible with a number of web frameworks, simply implemented, light on server resources and fairly fast.<br>To install Gunicorn using pip , run the Command in Terminal</p><pre>pip install gunicorn</pre><h4>Login Heroku</h4><p>To login Heroku CLI , you first need to run login command in terminal which will take you to login page in browser:</p><pre>heroku login</pre><h4>Create App</h4><p>To create app and PostgreSql on Heroku you need to run following commands.</p><pre>heroku create &lt;appname&gt; <br>heroku addons:create heroku-postgresql:hobby-dev --app &lt;appname&gt;</pre><h4>Get URI</h4><p>To get URI details of your Postgresql on heroku</p><pre>heroku config --app appname<br># Add details to your app production file</pre><h4>Config Files</h4><p>You need to add 3 files to you base directory which will help Heroku to deploy your App:</p><ol><li>Procfile — Procfile tells Heroku what commands should be run ( without any extension )</li><li>requirements.txt — Libraries to install with their supported Versions.</li><li>runtime.txt — Python Version to use .</li></ol><h4>Create Procfile</h4><pre>touch Procfile<br># Add this<br>web: gunicorn app:app</pre><h4>Create requirements.txt</h4><pre>pip freeze &gt; requirements.txt</pre><h4>Create runtime.txt</h4><pre>touch runtime.txt<br># Add this<br>python-&lt;your python Version&gt;</pre><h4>Deploy with Git</h4><pre>git init<br>git add . &amp;&amp; git commit -m &#39;Deploy&#39;<br>heroku git:remote -a &lt;appname&gt;<br>git push heroku master</pre><h3>Upload The Database</h3><p>Congrats……!!!!!!!<br>You have successfully created your first flask app with Postgre but you still need to upload you Data which you uploaded on local Postgre to Heroku.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*KVUWQQ_02E1bqqof8ZFTKA.png" /></figure><ul><li>Create Backup of Dataset</li><li>Fill the Desired Name.sql with format as “Plain”</li><li>In Advanced Settings , under the Queries ,set “Use Insert Command” as True.</li><li>Once you successfully Exported the Database as SQL format you can Import this data to Heroku PostgreSQL.</li><li>Once executed it start Inserting Rows to your app(Heroku Limit- 10,000 rows)</li></ul><pre>heroku pg:psql --app APP_NAME &lt; SQL_FILE_NAME.sql</pre><p>To run the Website , you can either check the website or run the command:</p><pre>heroku open --app APP_NAME</pre><blockquote><strong>You have Successfully Scraped the Lyrics , Build the App and deployed it on Heroku.</strong></blockquote><blockquote><strong>Well Done …!!!</strong></blockquote><h3>Previous Tutorials.</h3><h4>Tutorial 1 — Introduction</h4><p>In<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-799ffd367067"> Previous Tutorials</a> , we Understood Basic Concept of Web Scraping and Created Simple function to Extract lyrics from page using requests and BeautifulSoup.</p><h4>Tutorial 2 — Rotating Requests with Pool of Header and Proxies in Python.</h4><p>To Create a Bigger Project which can scrap thousands of Pages from the Internet You need more Clear Work Environment by using the concepts of OOP and Inheritance. You also need to have more Detailed Knowledge of Header Pooling and Proxy Pooling to remain Anonymous from the Server which we Already covered in the Second<a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0"> part of This Tutorial.</a></p><h4>Tutorial 3 — Work Environment and Asynchronous I/O Programming</h4><p>We will do Asynchronous I/O Programming to Increase your Scrapping speed Which will be covered in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7?postPublishedType=initial"> Third part of this Tutorial</a>.</p><h4>Tutorial 4 — Automated Site Scraping</h4><p>With all the concepts studied in previous Tutorial , we will create actual Automated Scraper to download and save lyrics from web page in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1"> Forth part of this Tutorial</a>.</p><h4>Tutorial 5 — API Access</h4><p>To easily access the Lyrics from the internet , We will Create Flask API and front end to access our Scrapped Lyrics in <a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40">Fifth Part of this Tutorial</a>.</p><h4>Tutorial 6 — Host our Flask server on Heroku</h4><p>To provide Easy Access of Lyrics we will host our Flask Server over Heroku.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*coYa-VLeyzSyzAkG" /></figure><h3>Final Words</h3><p>Thanks for reading this post, we would love to hear your feedback. Feel free to Comment on any Issues.</p><p>Give us a clap if you enjoyed it:) . Follow us to get our Latest Articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0e3cc8ce9f6" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-deploy-a-python-web-app-using-flask-and-a0e3cc8ce9f6">Beginner to Advance — Web Scraping Guide in Python: Deploy a Python Web App using Flask and…</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner to Advance — Web Scraping Guide in Python: Build and Deploy a Python Web App using Flask…]]></title>
            <link>https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40?source=rss-f5f76b51b980------2</link>
            <guid isPermaLink="false">https://medium.com/p/202ffdf8fd40</guid>
            <category><![CDATA[lyrics]]></category>
            <category><![CDATA[heroku]]></category>
            <category><![CDATA[flask]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Kaus Pathak]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 09:15:54 GMT</pubDate>
            <atom:updated>2020-06-23T14:28:26.353Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*l0FcmzZD7RPvKfpv" /></figure><h3>Beginner to Advance — Web Scraping Guide in Python: Build and Deploy a Python Web App using Flask and Postgres.</h3><p>In Previous Tutorials, we created a Scraping project to Download lyrics from AZLyrics which save lyrics in JSON format . But we also need to create a Website and API to our data to better search lyrics in our data. So for creating Web — Based Interface and RESTful API , we will use Flask and Postgresql and Deploy our interface on Heroku.</p><h4>Why is Flask a good web framework choice?</h4><p>Flask is a fast ,lightweight and<a href="https://www.fullstackpython.com/flask.html"> Beginners friendly</a> web Framework written in Python which uses<a href="https://www.tutorialspoint.com/flask/flask_overview.htm"> Werkzeug WSGI toolkit and Jinja2 template engine</a>. Starter code to write the “Hello World” Program in Flask is very sample.</p><pre>from flask import Flask<br>app = Flask(__name__)<br>@app.route(‘/’)<br>def hello_world():<br>   return ‘Hello, World!’<br>if __name__ == ‘__main__’:<br>   app.run()</pre><h4>PostgreSQL</h4><p>PostgreSQL is a free and open-source relational database management system emphasizing extensibility and SQL compliance. It is freely Available in Heroku upto 10,000 Rows which we learn about in the Next Section.</p><h3>Installing Flask and PostgreSQL</h3><p>Installing flask is simple and Straightforward in python using PIP. You just need to activate the local python Environment (If you are using) and use pip command to install Flask</p><pre>pip install flask</pre><p>Using PostgreSQL with Flask can be a little Complicated but there are tons of help and Blogs you can look into in case of an Error. We will use the<a href="https://stackabuse.com/using-sqlalchemy-with-flask-and-postgresql/"> <em>Flask-SQLAlchemy</em></a> extension to connect our API to a Postgres database.</p><pre>pip install psycopg2-binary ,flask-sqlalchemy, Flask-Migrate<br>sudo apt-get install postgresql postgresql-contrib</pre><p>We will be using Pgadmin4 as Client Which is popular and feature rich Open Source administration and development platform for PostgreSQL.<br>Creating a Superuser for PostgreSQL.</p><pre>sudo -u postgres createuser — superuser <strong><em>name_of_user</em></strong></pre><p>And create a database using created user account.</p><pre>sudo -u <strong><em>name_of_user</em></strong> createdb <strong><em>lyrics</em></strong></pre><p>Now running <strong>pgadmin4</strong> , you will be able to see your first Database .</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/0*LHD4g_iafzKOwBWK" /></figure><p>Now we will create a new folder called <strong>Web_App</strong> where we will create our flask Project. We also need to create Folders <strong>static</strong> and <strong>template </strong>where we will create our HTML and CSS files.</p><p>Now create the file <strong>app.py</strong> inside the Web_App folder and put the following code inside it.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/138c11940fe77d332e322210a2510b95/href">https://medium.com/media/138c11940fe77d332e322210a2510b95/href</a></iframe><p>But first we need to create a table in our Database by following Commands.</p><pre>&gt;&gt; from app import db<br>&gt;&gt; db.create_all()</pre><p>You can Check the table in <strong>pgadmin4</strong> by the name Lyrics_dataset. But before we run our app.py file we need to commit data we scraped to our Database. We also need to create a template for our Front End Website.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/792c4b36f23920d8fcab4a9103bc819a/href">https://medium.com/media/792c4b36f23920d8fcab4a9103bc819a/href</a></iframe><p>This code will import data from JSON to Table <strong>lyrics_dataset </strong>which can be accessed from our website. Now finishing our back end we will create a front end to access our website.</p><p>We will use the free Template<a href="https://getbootstrap.com/docs/4.5/examples/blog/"> Blog</a> by Bootstrap which is free and easy to start as our Parent Template and extend all the websites as the Child Template. You also need to place the files blog.css and bootstrap.css in the static folder and create all the HTML files in templates folder.</p><h4>Base Template</h4><p>This template, which we’ll call template.html, defines a simple HTML skeleton document that you might use for a simple page. It’s the job of “child” templates to fill the empty blocks with content:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ed95168beaa6483619cdd69810529715/href">https://medium.com/media/ed95168beaa6483619cdd69810529715/href</a></iframe><p>In this example, the {% block %} tags define four blocks that child templates can fill in. All the block tag does is tell the template engine that a child template may override those portions of the template.</p><h4>Child Template</h4><p>Extending the base template , we will also create the our other pages replacing the block {% block repeated %} :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/0*t6dpL0w2jINXPOIJ" /></figure><ul><li><a href="https://gist.github.com/terminate9298/80a4b512115b031cf59075a480c72fd5">main.html</a> — Display the Link of songs with searched Keywords in their name.</li><li><a href="https://gist.github.com/terminate9298/b8ed8ace918da054b5d72699935fb227">search.html </a>— Display the Link of songs with searched Keywords in their Lyrics.</li><li><a href="https://gist.github.com/terminate9298/647ae490fa9d8636aa0e0a10fe5b1f69">singer.html</a> — Display the Link of songs by Singer.</li><li><a href="https://gist.github.com/terminate9298/1cd69b90a26c2257a7cd85fb709dd835">lyrics.html </a>— Display the Lyrics of songs by ID.</li><li><a href="https://gist.github.com/terminate9298/fcc177e0b9a5be859586712bf8671676">index.html</a> — Index page displayed as homepage of website.</li></ul><p>If you have successfully completed the steps you will be able to run your code now. To run Flask server you can now run the app.py by typing :</p><pre>python app.py</pre><p>To run the Postgre , you can directly start <strong>pgadmin4</strong> and that will start PostgreSQL server on your system.</p><h3>Checking our Website</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/718/0*E6ayXkoPs28lX8M2" /></figure><p>If you are able to check your website on server using your browser :</p><pre><a href="http://localhost:5000/">http://localhost:5000/</a></pre><p>You can also get lyrics of song using the API like :</p><pre><a href="http://127.0.0.1:5000/api/lyrics/id/453">http://127.0.0.1:5000/api/lyrics/id/453</a></pre><blockquote><strong>You have Successfully Built a Python Web App using Flask and Postgres.</strong></blockquote><blockquote><strong>Well Done …!!!</strong></blockquote><h3>Moving Forward from Here.</h3><h4>Tutorial 1 — Introduction</h4><p>In<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-799ffd367067"> Previous Tutorials</a> , we Understood Basic Concept of Web Scraping and Created Simple function to Extract lyrics from page using requests and BeautifulSoup.</p><h4>Tutorial 2 — Rotating Requests with Pool of Header and Proxies in Python.</h4><p>To Create a Bigger Project which can scrap thousands of Pages from the Internet You need more Clear Work Environment by using the concepts of OOP and Inheritance. You also need to have more Detailed Knowledge of Header Pooling and Proxy Pooling to remain Anonymous from the Server which we Already covered in the Second<a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0"> part of This Tutorial.</a></p><h4>Tutorial 3 — Work Environment and Asynchronous I/O Programming</h4><p>We will do Asynchronous I/O Programming to Increase your Scrapping speed Which will be covered in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7?postPublishedType=initial"> Third part of this Tutorial</a>.</p><h4>Tutorial 4 — Automated Site Scraping</h4><p>With all the concepts studied in previous Tutorial , we will create actual Automated Scraper to download and save lyrics from web page in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1"> Forth part of this Tutorial</a>.</p><h4>Tutorial 5 — API Access</h4><p>To easily access the Lyrics from the internet , We will Create Flask API and front end to access our Scrapped Lyrics in <a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40">Fifth Part of this Tutorial</a>.</p><h4>Tutorial 6 — Host our Flask server on Heroku</h4><p>To provide Easy Access of Lyrics we will host our Flask Server over Heroku in <a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-deploy-a-python-web-app-using-flask-and-a0e3cc8ce9f6">Sixth Part of this Tutorial.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*dfjc4QahUIQE2U_9" /></figure><h3>Final Words</h3><p>Thanks for reading this post, we would love to hear your feedback. Feel free to Comment on any Issues.</p><p>Give us a clap if you enjoyed it:) . Follow us to get our Latest Articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=202ffdf8fd40" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40">Beginner to Advance — Web Scraping Guide in Python: Build and Deploy a Python Web App using Flask…</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner to Advance — Web Scraping Guide in Python: Automated Lyrics Scraper.]]></title>
            <link>https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1?source=rss-f5f76b51b980------2</link>
            <guid isPermaLink="false">https://medium.com/p/809163f279a1</guid>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[lyrics]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[asynchronous]]></category>
            <dc:creator><![CDATA[Kaus Pathak]]></dc:creator>
            <pubDate>Mon, 15 Jun 2020 13:11:37 GMT</pubDate>
            <atom:updated>2020-06-23T14:26:27.310Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O5ngnJfi1EEi2GmX4-N53A.jpeg" /></figure><h3>Beginner to Advance — Web Scraping Guide in Python: Automated Lyrics Scraper.</h3><p>In Previous tutorials, we learned basics of web scraping , Rotating requests and using Async programming. Now we will use these skills to scrap Lyrics from AZLyrics site and save scrapped lyrics in JSON format.</p><h3>Workflow</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*HZBrDaUHqEWDzapXO4Q89g.png" /></figure><p>We will make automated process Which accept Singers URL and Save there songs and Album List and start scraping all the songs on there Page. Here is how sample page for singer looks like.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*esOKPmIKvDtuor8otGtj8g.png" /></figure><p>Since we have already developed 2 classes in <em>bin/proxies.py</em> , we wll create a new main class inside <em>bin/main.py</em> named <em>AZLyrics</em> and inherit Previous class <em>Proxy_Checker</em>.</p><h4>Part 1 — Parsing Main pages and Collecting Songs URLs from Inserted URLs.</h4><p>Here is our new class will look like :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c69ce87cd9470d7400271b5bc03282c/href">https://medium.com/media/7c69ce87cd9470d7400271b5bc03282c/href</a></iframe><p>Here we defined function <em>az_load_data(self) </em>to load json data inside az_data and az_lyrics. We will use these variables to append data and save these variables to backup our data.<br>The function <em>az_logger(self)</em> will allow us to create log file to check our progress in script.<br>Now we will define new function to requests URL but since most of our requests are going to get failed , we will make requests with new Proxy and Header until we successfully get data from site. Also if recognized as bot site will send Alert Page , which we also need to handle as it looks like a normal page with status code 200 but is no use to us , as it doesn’t have any actual data in it. So the function will look like :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c23be8ecdf32f6b5776f5d91a131d1c2/href">https://medium.com/media/c23be8ecdf32f6b5776f5d91a131d1c2/href</a></iframe><p>Using this function we will request the pages from server but we still need to parse the requests and filter data of our need. For this we will create other function <em>az_songs_by_list(self)</em> to parse requests and save all URLs from page.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/864a4d47e07477298584b5ff744f854d/href">https://medium.com/media/864a4d47e07477298584b5ff744f854d/href</a></iframe><p>Function <em>az_songs_by_list </em>will save data in dictionary and save URLs inside <em>az_data[‘simple_urls’]</em> array. With <em>add_urls()</em> , we can accept and save the artists URL .</p><p>To run the script we have so far created if everything is correct , We will use the command.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d84d4856982f81abcf2b907b5c3e3af9/href">https://medium.com/media/d84d4856982f81abcf2b907b5c3e3af9/href</a></iframe><p>If everything is Correct, you should be able to start scrapping the site and check the progress in <em>json_data/data_to_scrap.json</em> and log will be Updated inside<em> log_data/main.log .</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/481/1*mfT9e9_DEtVJghkKs_6uDg.png" /></figure><p>After the Update , your <em>json_data/data_to_scrap.json file </em>will look something similar .<br>As you can see by Scraping 3 singers , we were able to scrap 1686 Songs urls.<br>Now we will use these urls to Scrap lyrics from site.</p><h4>Part 2— Scraping URLs and Collecting Lyrics by Asyncio Programming.</h4><p>With experience from previous tutorials we will use Asyncio Concepts to scrap lyrics.</p><ul><li><strong>lyrics_from_link() —</strong> Function that accepts Parsed Website and Create Dictionary of details about song that include its Lyrics.</li><li><strong>get_batch_lyrics() </strong>— Function to create Threads and run <strong>lyrics_from_link() </strong>function in concurrency .</li></ul><blockquote>Note — You should scrap proxies time to time since they get updated and needed to be refreshed in few hours.</blockquote><p>The Complete Script will be :</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ee38e1b0ee90e2d39aa2916cf20b809/href">https://medium.com/media/7ee38e1b0ee90e2d39aa2916cf20b809/href</a></iframe><p>Now since we have completed our code we will create a <em>main.py </em>file to access all our codes easily<em>. </em>If correct ,Running the Code below would start scraping the urls and you can check the progress inside logs. Once Finished you will see update in<em> json_data/data_lyrics.json </em>file.</p><pre>import json<br>from bin.azlyrics import *</pre><pre>if __name__ == “__main__”:<br> azlyrics = AZLyrics()<br> azlyrics.start_scrapping()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/565/1*lr4UtCntTl43x675newjrw.png" /></figure><p>With This Script , i was able to scrap around 16k songs lyrics in 2 hours about any Error.<br>I used max_workers value set to 100 but you can also increase this value based on your system and Bandwidth.</p><p>You can also find the complete code on <a href="https://github.com/terminate9298/azlyrics_scraper">this Github</a> Link.</p><p><a href="https://github.com/terminate9298/azlyrics_scraper">terminate9298/azlyrics_scraper</a></p><blockquote><strong>You have Successfully written the Code to Scrap AZLyrics without getting blocked.<br>Well Done…!!!</strong></blockquote><h3>Moving Forward from Here.</h3><h4>Tutorial 1 — Introduction</h4><p>In<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-799ffd367067"> Previous Tutorials</a> , we Understood Basic Concept of Web Scraping and Created Simple function to Extract lyrics from page using requests and BeautifulSoup.</p><h4>Tutorial 2 — Rotating Requests with Pool of Header and Proxies in Python.</h4><p>To Create a Bigger Project which can scrap thousands of Pages from the Internet You need more Clear Work Environment by using the concepts of OOP and Inheritance. You also need to have more Detailed Knowledge of Header Pooling and Proxy Pooling to remain Anonymous from the Server which we Already covered in the Second<a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0"> part of This Tutorial.</a></p><h4>Tutorial 3 — Work Environment and Asynchronous I/O Programming</h4><p>We will do Asynchronous I/O Programming to Increase your Scrapping speed Which will be covered in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7?postPublishedType=initial"> Third part of this Tutorial</a>.</p><h4>Tutorial 4 — Automated Site Scraping</h4><p>With all the concepts studied in previous Tutorial , we will create actual Automated Scraper to download and save lyrics from web page in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1"> Forth part of this Tutorial</a>.</p><h4>Tutorial 5 — API Access</h4><p>To easily access the Lyrics from the internet , We will Create Flask API and front end to access our Scrapped Lyrics in <a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40">Fifth Part of this Tutorial</a>.</p><h4>Tutorial 6 — Host our Flask server on Heroku</h4><p>To provide Easy Access of Lyrics we will host our Flask Server over Heroku in <a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-deploy-a-python-web-app-using-flask-and-a0e3cc8ce9f6">Sixth Part of this Tutorial.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*q9SySkNwsu0Y5uBQ" /></figure><h3>Final Words</h3><p>Thanks for reading this post, we would love to hear your feedback. Feel free to Comment any Issues.<br>Give us a clap if you enjoyed it :) . Follow us to get our Latest Articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=809163f279a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1">Beginner to Advance — Web Scraping Guide in Python: Automated Lyrics Scraper.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner to Advance — Web Scraping Guide in Python : Introduction to Asynchronous Programming]]></title>
            <link>https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7?source=rss-f5f76b51b980------2</link>
            <guid isPermaLink="false">https://medium.com/p/24bce03dafa7</guid>
            <category><![CDATA[asyncio]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[asynchronous]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-scraping]]></category>
            <dc:creator><![CDATA[Kaus Pathak]]></dc:creator>
            <pubDate>Sun, 14 Jun 2020 22:13:02 GMT</pubDate>
            <atom:updated>2020-06-23T14:27:58.758Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4DFFM_HJCacB12CN" /><figcaption>Photo by <a href="https://unsplash.com/@hiteshchoudhary?utm_source=medium&amp;utm_medium=referral">Hitesh Choudhary</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Beginner to Advance — Web Scraping Guide in Python : Introduction to Asynchronous Programming</h3><p>This tutorial will provide an overview of asynchronous programming including its conceptual elements, the basics of Python’s async APIs, and an example implementation of an asynchronous web scraper.<br>Synchronous programs are straightforward: start a task, wait for it to finish, and repeat until all tasks have been executed. However, waiting wastes valuable CPU cycles. Asynchronous programs remedy this problem by using context switching to interleave tasks in order to improve program responsiveness, and minimize processor idle time and total program execution time.<br>In Synchronous programming , if we set timeout for one request to 10 seconds , Then our system is sitting Ideally for 10 seconds which time can used to process the previous requests and send new Requests.</p><h3>Asynchronous Programming in Python</h3><p>In <a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0">Previous tutorials</a>, we implemented Requests Async programming which allows you to write concurrent code that runs in a single thread. The first advantage compared to multiple threads is that you decide where the scheduler will switch from one task to another, which means that sharing data between tasks it’s safer and easier. The main libraries for implementing Asyncio Web Scrapping is aiohttp . The Sample code for aiohttp is Attached below:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b9ca25f7aad40813da7cb2da35e862f1/href">https://medium.com/media/b9ca25f7aad40813da7cb2da35e862f1/href</a></iframe><h3>Complications with aiohttp Library</h3><ul><li>Although aiohttp Library was created to handle Multiple requests , it wasn’t created to send each requests from separate Proxy and Header.</li><li>The concept of aiohttp is relatively new in python and there is limited support for Asyncio Programming in python.</li><li>Relatively lesser number of articles are written for Complex Concurrent Functions in python and but more for Serial Programming.</li></ul><p>So will implement our Asyncio Programming without aiohttp with process <a href="https://www.hackernoon.com/how-to-run-asynchronous-web-requests-in-parallel-with-python-3-5-without-aiohttp-264dc0f8546">explained in this Tutorial</a>. But here is Sample Code of what we are going to follow.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9483eb9e96638b193fee70b2c92894db/href">https://medium.com/media/9483eb9e96638b193fee70b2c92894db/href</a></iframe><p><a href="https://docs.python.org/3.4/library/concurrent.futures.html#concurrent.futures.ThreadPoolExecutor">ThreadPoolExecutor</a> is an <a href="https://docs.python.org/3.4/library/concurrent.futures.html#concurrent.futures.Executor">Executor</a> subclass that uses a pool of threads to execute calls asynchronously. It uses pool of most <em>max_workers</em> threads to execute calls. <br>ThreadPoolExecutor provide a simple abstraction around spinning up multiple threads and using these threads to perform tasks in a concurrent fashion. Adding threading to your application can help to drastically improve the speed of your application when used in the right context. By using multiple threads we can speed up applications which face an input/output based bottleneck.</p><h3>Going Deeper</h3><p>In our previous tutorial we created a class to scrap User-Agents and Proxies from other sites. But most of the proxies we scraped don’t work or the ports are blocked on the server. So to filter the working proxies from the proxies we scraped, we must send request and separate working proxies by inheriting the proxies class and expanding the class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17117ae942f59018bbbac88aa8913160/href">https://medium.com/media/17117ae942f59018bbbac88aa8913160/href</a></iframe><p>Here we have used max_workers as 50 to limit number of threads as 50 but you can also increase this value for System with higher processing power and higher Bandwidth. This piece of code will be get appended in bin/proxies.py file.</p><blockquote><strong>You have Successfully implemented Async Function in Python.<br>Well Done…!!!</strong></blockquote><h3>Moving Forward from Here.</h3><h4>Tutorial 1 — Introduction</h4><p>In<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-799ffd367067"> Previous Tutorials</a> , we Understood Basic Concept of Web Scraping and Created Simple function to Extract lyrics from page using requests and BeautifulSoup.</p><h4>Tutorial 2 — Rotating Requests with Pool of Header and Proxies in Python.</h4><p>To Create a Bigger Project which can scrap thousands of Pages from the Internet You need more Clear Work Environment by using the concepts of OOP and Inheritance. You also need to have more Detailed Knowledge of Header Pooling and Proxy Pooling to remain Anonymous from the Server which we Already covered in the Second<a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0"> part of This Tutorial.</a></p><h4>Tutorial 3 — Work Environment and Asynchronous I/O Programming</h4><p>We will do Asynchronous I/O Programming to Increase your Scrapping speed Which will be covered in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7?postPublishedType=initial"> Third part of this Tutorial</a>.</p><h4>Tutorial 4 — Automated Site Scraping</h4><p>With all the concepts studied in previous Tutorial , we will create actual Automated Scraper to download and save lyrics from web page in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1"> Forth part of this Tutorial</a>.</p><h4>Tutorial 5 — API Access</h4><p>To easily access the Lyrics from the internet , We will Create Flask API and front end to access our Scrapped Lyrics in <a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40">Fifth Part of this Tutorial</a>.</p><h4>Tutorial 6 — Host our Flask server on Heroku</h4><p>To provide Easy Access of Lyrics we will host our Flask Server over Heroku in <a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-deploy-a-python-web-app-using-flask-and-a0e3cc8ce9f6">Sixth Part of this Tutorial.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SQPN6AQo4rL5eEf1" /></figure><h3>Final Words</h3><p>Thanks for reading this post, we would love to hear your feedback. Feel free to Comment any Issues.<br>Give us a clap if you enjoyed it :) . Follow us to get our Latest Articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24bce03dafa7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7">Beginner to Advance — Web Scraping Guide in Python : Introduction to Asynchronous Programming</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner to Advance : Web Scraping Guide in Python.]]></title>
            <link>https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0?source=rss-f5f76b51b980------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba24dca5dce0</guid>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[lyrics]]></category>
            <category><![CDATA[python3]]></category>
            <dc:creator><![CDATA[Kaus Pathak]]></dc:creator>
            <pubDate>Sat, 13 Jun 2020 21:20:55 GMT</pubDate>
            <atom:updated>2020-06-23T14:27:21.553Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lNmGeqS7Rvo4xyb3" /><figcaption>Photo by <a href="https://unsplash.com/@hiteshchoudhary?utm_source=medium&amp;utm_medium=referral">Hitesh Choudhary</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Beginner to Advance — Web Scraping Guide in Python: Rotating Requests with pool of Headers and Proxies.</h3><p>A common problem faced by web scrapers is getting blocked by websites while scraping them. Server Identifies the User using there request Header and Proxy client Blocking the client if categories the Client as Bot. There are many techniques to prevent getting blocked, like</p><ul><li>Rotating IP addresses</li><li>Using Proxies</li><li>Rotating and Spoofing user agents</li></ul><p>Using proxies and rotating IP addresses in combination with rotating user agents can help you get scrapers past most of the anti-scraping measures and prevent being detected as a scraper.<br>The concept of rotating IP addresses while scraping is simple — you can make it look to the website that you are not a single ‘bot’ or a person accessing the website, but multiple ‘real’ users accessing the website from multiple locations.</p><h3>Tutorial 2 — Rotating Requests with pool of Headers and Proxies to Remain Anonymous.</h3><h4>First Look</h4><p>In <a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-799ffd367067">previous tutorial</a>, we Learned to get web page using requests.get Command and parse that Request using BeautifulSoup. Now to Rotate the Requests we need to pass Header and Proxy arguments in Requests.get</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a17a9b30dcba2fa550da81b50b8b828/href">https://medium.com/media/2a17a9b30dcba2fa550da81b50b8b828/href</a></iframe><p>Here , the User-Agent is String which tells server lot about your Browser and Operating System. Referrer tells Server about location the Url is referred from.<br>For example if you search the page on Search Engine and then click on link URL from that webpage , The referrer will be set to your Search Engine.<br>You can check you Header details by opening Inspect Element. It will look something like this inside Firefox Browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*qMcA6DtDiaLlHeynRRoLYw.png" /></figure><p>Here you can see the Referer is set to https://duckduckgo.com and User-Agent is Unique for your Browser with many other Request Headers.<br>When argument proxies is passed , the provided Proxy will be used to get requests . In our Project we will be using Public Proxies to send out request but if you are planning to Scrap Sites like Google or Facebook , I recommend using Premium Proxies. Now the Public Proxies are defined in 3 Categories.</p><ol><li><strong>Transparent Proxy</strong> – A transparent proxy is a server that sits between your computer and the internet and redirects your requests and responses without modifying them. It sends your real IP address in the HTTP_X_FORWARDED_FOR header, this means a website that does not only determine your REMOTE_ADDR but also checks for specific proxy headers that will still know your real IP address. The HTTP_VIA header is also sent, revealing that you are using a proxy server.</li><li><strong>Anonymous Proxy</strong> – An anonymous proxy does not send your real IP address in the HTTP_X_FORWARDED_FOR header, instead, it submits the IP address of the proxy or it’ll just be blank. The HTTP_VIA header is sent with a transparent proxy, which would reveal you are using a proxy server. An anonymous proxy server does not tell websites your real IP address anymore. This can be helpful to just keep your privacy on the internet. The website can still see you are using a proxy server, but in the end, it does not really matter as long as the proxy server does not disclose your real IP address. If someone really wants to restrict page access, an anonymous proxy server will be detected and blocked.</li><li><strong>Elite Proxy</strong> – An elite proxy only sends REMOTE_ADDR header while the other headers are empty. It will make you seem like a regular internet user who is not using a proxy at all. An elite proxy server is ideal to pass any restrictions on the internet and to protect your privacy to the fullest extent. You will seem like a regular internet user who lives in the country that your proxy server is running in.</li></ol><h4>Concepts for getting User Agents and Proxies from Internet</h4><ol><li><strong>User Agents </strong>— To Collect User Agents from Internet , we will use <a href="https://developers.whatismybrowser.com/">whatismybrowser.com/</a> which have collection of millions of user agents and have categorized them , based on some of the things detected about them — Operating System, Browser, Hardware Type, Browser Type, and so on.<br>You can hand Pick the few User Agents or scrap few hundred User Agents to create poll of User Agents, the complete Code of which is Provided Below.</li><li><strong>Proxies </strong>— There are lot of websites where you can get free Proxies to use while scrapping. Some of them are <a href="http://pubproxy.com/">PubProxy</a> , <a href="https://www.proxyscrape.com/home">ProxyScrape</a> , <a href="https://free-proxy-list.net/">free-proxy-list</a>.<br>You need to create functions to scrap these Website as they are needed to be scrapped Continuously scrapped through out the Program.</li><li><strong>Logging</strong> — To maintain Automated Project we need to setup Logging Features in Python to Check out Progress and Errors while running the Scripts. I encourage little Practice of Logging if you haven’t practiced Logging in Past. You can Look <a href="https://docs.python.org/2/howto/logging.html">Official Documentation</a> and <a href="https://www.geeksforgeeks.org/logging-in-python/">GeeksforGeeks </a>for some Support.</li><li><strong>Python OOP’s Concept </strong>— We will use <a href="https://www.javatpoint.com/python-oops-concepts">Object Oriented Programming </a>concepts like Inheritance to create class and Objects in our Program.</li><li><strong>JSON Concepts —</strong> To save Output data in Drive.</li></ol><h4>First Look of Our Working Directory</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/311/1*GzKqRUUE4NQNyIzmUT3oGQ.png" /></figure><ul><li>bin — To write code Classes and Functions.</li><li>json_data — To store Processed and UnProcessed Data to disk.</li><li>log_data — To check Progress and Errors in our Script.</li><li>main.py — Main file from where we will execute our program.</li></ul><p>We also need to create script to place data inside JSON . You can use your format but below code run and prepare each JSON for future use.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4100ad1200a4ec8f4dce593f194c146d/href">https://medium.com/media/4100ad1200a4ec8f4dce593f194c146d/href</a></iframe><h3>Working Code</h3><p>Each of these will help you too easily maintain data for rest of series. You can Scrap the user agents from links provided in code or download the scrapped data from here.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f345d77e1f98624283ca9e64f5ed7b3f/href">https://medium.com/media/f345d77e1f98624283ca9e64f5ed7b3f/href</a></iframe><p>If you successfully compile this Script in <em>bin/proxies.py</em> , this will save scrap the proxies from internet and save it in JSON format. You can check project progress in <em>log_data/proxies.log <br></em>Program use free-proxy-list.com to scrap latest proxies but you can use pubproxy or proxyscrape to scrap latest proxies but <em>get_free_p_l() </em>Work fine.</p><blockquote><strong>You have Successfully created Class to Change Proxy and Header while Scrapping .<br>Well Done …!!!</strong></blockquote><h3>Moving Forward from Here.</h3><h4>Tutorial 1 — Introduction</h4><p>In<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-799ffd367067"> Previous Tutorials</a> , we Understood Basic Concept of Web Scraping and Created Simple function to Extract lyrics from page using requests and BeautifulSoup.</p><h4>Tutorial 2 — Rotating Requests with Pool of Header and Proxies in Python.</h4><p>To Create a Bigger Project which can scrap thousands of Pages from the Internet You need more Clear Work Environment by using the concepts of OOP and Inheritance. You also need to have more Detailed Knowledge of Header Pooling and Proxy Pooling to remain Anonymous from the Server which we Already covered in the Second<a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0"> part of This Tutorial.</a></p><h4>Tutorial 3 — Work Environment and Asynchronous I/O Programming</h4><p>We will do Asynchronous I/O Programming to Increase your Scrapping speed Which will be covered in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7?postPublishedType=initial"> Third part of this Tutorial</a>.</p><h4>Tutorial 4 — Automated Site Scraping</h4><p>With all the concepts studied in previous Tutorial , we will create actual Automated Scraper to download and save lyrics from web page in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1"> Forth part of this Tutorial</a>.</p><h4>Tutorial 5 — API Access</h4><p>To easily access the Lyrics from the internet , We will Create Flask API and front end to access our Scrapped Lyrics in <a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40">Fifth Part of this Tutorial</a>.</p><h4>Tutorial 6 — Host our Flask server on Heroku</h4><p>To provide Easy Access of Lyrics we will host our Flask Server over Heroku in <a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-deploy-a-python-web-app-using-flask-and-a0e3cc8ce9f6">Sixth Part of this Tutorial.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*378uvUh61PtXDtFj" /><figcaption>Photo by <a href="https://unsplash.com/@peet818?utm_source=medium&amp;utm_medium=referral">Pete Pedroza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Final Words</h3><p>Thanks for reading this post, we would love to hear your feedback. Feel free to Comment any Issues.<br>Give us a clap if you enjoyed it:) . Follow us to get our Latest Articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba24dca5dce0" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0">Beginner to Advance : Web Scraping Guide in Python.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Beginner to Advance : Web Scraping Guide in Python.]]></title>
            <link>https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-799ffd367067?source=rss-f5f76b51b980------2</link>
            <guid isPermaLink="false">https://medium.com/p/799ffd367067</guid>
            <category><![CDATA[web]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[lyrics]]></category>
            <category><![CDATA[scrapping]]></category>
            <dc:creator><![CDATA[Kaus Pathak]]></dc:creator>
            <pubDate>Thu, 11 Jun 2020 22:15:03 GMT</pubDate>
            <atom:updated>2020-06-23T14:26:17.612Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Jh6uoU-FqnEZlVdm" /><figcaption>Photo by <a href="https://unsplash.com/@vidarnm?utm_source=medium&amp;utm_medium=referral">Vidar Nordli-Mathisen</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Beginner to Advance — Web Scraping Guide in Python : Introductory guide to Scrap AZLyrics.</h3><h3>Introduction</h3><p>There are thousands of tons of information on the Web. It’s been growing beyond the most daring predictions. And if you want to keep pace with the times, you need to process information faster than others.</p><p>Over the past years there is development of several big projects which involve scraping and data processing. They were developed for completely different industries, and our approach here is too find most optimal solution for all of them.</p><h3><strong>Main tools we will Learn About:</strong></h3><ul><li>Python (3.5)</li><li><a href="https://pypi.org/project/beautifulsoup4/"><em>BeautifulSoup</em></a><em> </em>library for handling the text extraction from the web page’s source code (HTML and CSS)</li><li><a href="https://pypi.org/project/requests/"><em>requests</em></a><em> </em>library for handling the interaction with the web page (Using HTTP requests)</li><li>API calls — for enriching our data</li><li>Proxy and User Agents rotations — generating random headers to bypass Security</li></ul><h3>Tutorial 1 — Beginner’s Tutorial</h3><p>Feel free to choose website of your choice.But for this Project we are Selecting <a href="https://www.azlyrics.com/">This</a> website. <strong><em>Note — This tutorial is for Educational Purpose only and I don’t advice to scrape this website for any Illegal Activity</em></strong><em> </em>.<br>So First Look of What we Are Scraping.</p><figure><img alt="https://www.azlyrics.com/" src="https://cdn-images-1.medium.com/max/1024/1*Jmb-_qnWlbJE-UISyWWZUg.png" /><figcaption><a href="https://www.azlyrics.com/">https://www.azlyrics.com/</a></figcaption></figure><p>AZLyrics Provide Plain Lyrics of song with Functionality to Search song and get list of all the songs sung by Singer. It is a simple site and don’t require any account or verification to get lyrics.</p><h4>Setting up the Environment</h4><p>Assuming you have already Installed <a href="https://docs.python.org/3/tutorial/venv.html">venv</a> but if you haven’t you can look up this <a href="https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/#installing-virtualenv">link</a> to how to install venv in your system.If you are not familiar with concept you can look up at this <a href="https://www.geeksforgeeks.org/python-virtual-environment/">link</a>.<br>Now Create a new Folder say python-azlyrics_scrapper and create venv inside it. This will make env Directory inside main Directory</p><pre>python3 -m venv env</pre><p>To Activate the Python environment Use the Code source env/bin/activate. <br>You also need to install Various Dependencies using Pip including requests , BeautifulSoup , Pandas , Regex inside your Development Environment.</p><pre>pip3 install requests regex pandas beautifulsoup4</pre><h4>Building Simple URL Extraction function to Extract Lyrics</h4><p>Create new file and save as print_lyrics.py. To Write Code you can use any Development IDE. <br>I prefer using Sublime Text or Atom but you can use IDE of your Choice. Now we can start by importing Libraries in our created File</p><pre>import requests <br>from bs4 import BeautifulSoup</pre><p>Now to Scrap a Web Page you have to understand some basics of HTML. If you open the Developers Tool or Inspect Element by pressing F12 , You can check the class of &lt;div&gt; which you wish to extract data from.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mi0R-BkmCXio9jKpmLQuxw.jpeg" /></figure><p>Here you can see the class “lyricsh” have inside the Singer Name in it and class “div-share” have song name inside it.</p><pre>&lt;div class=&quot;div-share&quot;&gt;&lt;h1&gt;&quot;I Cry&quot; lyrics&lt;/h1&gt;&lt;/div&gt;<br><br>&lt;div class=&quot;lyricsh&quot;&gt;<br>&lt;h2&gt;&lt;b&gt;Shayne Ward Lyrics&lt;/b&gt;&lt;/h2&gt;<br>&lt;/div&gt;</pre><p>So to get the Page from Server we have to use request Library to get Webpage from Internet using its URL . If you have some issues you can visit this <a href="https://www.pythonforbeginners.com/requests/using-requests-in-python/">link</a> to understand the <a href="https://2.python-requests.org/en/master/">requests Library</a> better.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/470b8b670cd2e81f3cbb01e6ae8f770a/href">https://medium.com/media/470b8b670cd2e81f3cbb01e6ae8f770a/href</a></iframe><p>In Above code we are requesting the URL by requests library and then saving the result in response . To run the file you can use the command</p><pre>python3 print_lyrics.py</pre><p>Now to Extract the details from response we have to use BeautifulSoup Library to parse HTML page which can be done using Command <br>BeautifulSoup(response.text , &#39;html.parser&#39;) to get html parsed text from response. Parsing Different Parts from webpage can be bit Confusing but with <a href="https://www.dataquest.io/blog/web-scraping-tutorial-python/">little Practice</a> you can get Desired details from webpage easily.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b834dcd7985a32a4d35232ee65a9980/href">https://medium.com/media/6b834dcd7985a32a4d35232ee65a9980/href</a></iframe><ul><li>Singer Name is Inside &lt;div&gt; with ‘lyricsh’</li><li>There is No unique class for Song and Lyrics You can use find_all Function to find all the &lt;div&gt; and get particular index to get the Details .<br>I used Hit and Trial to get above results but feel free to play with above Functions or get Unique Easier Way of doing it.</li><li>You can change the Url with others but general Structure of Page and Lyrics remain the same.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wcg53yxjw8FFZws_ID_aYQ.png" /></figure><p>The output of this file will be Singer Name , Song Name and Lyrics in terminal.</p><h4>Saving the Response</h4><p>For Saving this output to disk, i will be using JSON to Dump data but you can use CSV or text too. Using SQL to save data to disk might be Over Kill unless you are planning to Scrap and Manage Millions of Lyrics Dataset.<br>For few Thousands lyrics , JSON or CSV will work great. Complete Code Now will look like</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a795f3a241c8aba85c692ae5d9253be3/href">https://medium.com/media/a795f3a241c8aba85c692ae5d9253be3/href</a></iframe><p>This will create file ‘data.json’ in same directory with Singer and Lyrics of Song.</p><blockquote><strong>You have Successfully created Your First Web Scrapper .<br>Well Done…!!!</strong></blockquote><h3>Moving Forward from Here.</h3><h4>Tutorial 1 — Introduction</h4><p>In<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-799ffd367067"> Previous Tutorials</a> , we Understood Basic Concept of Web Scraping and Created Simple function to Extract lyrics from page using requests and BeautifulSoup.</p><h4>Tutorial 2 — Rotating Requests with Pool of Header and Proxies in Python.</h4><p>To Create a Bigger Project which can scrap thousands of Pages from the Internet You need more Clear Work Environment by using the concepts of OOP and Inheritance. You also need to have more Detailed Knowledge of Header Pooling and Proxy Pooling to remain Anonymous from the Server which we Already covered in the Second<a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-ba24dca5dce0"> part of This Tutorial.</a></p><h4>Tutorial 3 — Work Environment and Asynchronous I/O Programming</h4><p>We will do Asynchronous I/O Programming to Increase your Scrapping speed Which will be covered in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-introduction-to-asynchronous-programming-24bce03dafa7?postPublishedType=initial"> Third part of this Tutorial</a>.</p><h4>Tutorial 4 — Automated Site Scraping</h4><p>With all the concepts studied in previous Tutorial , we will create actual Automated Scraper to download and save lyrics from web page in<a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-automated-lyrics-scraper-809163f279a1"> Forth part of this Tutorial</a>.</p><h4>Tutorial 5 — API Access</h4><p>To easily access the Lyrics from the internet , We will Create Flask API and front end to access our Scrapped Lyrics in <a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-build-and-deploy-a-python-web-app-using-flask-202ffdf8fd40">Fifth Part of this Tutorial</a>.</p><h4>Tutorial 6 — Host our Flask server on Heroku</h4><p>To provide Easy Access of Lyrics we will host our Flask Server over Heroku in <a href="https://medium.com/@kaus.pathak_30409/beginner-to-advance-web-scraping-guide-in-python-deploy-a-python-web-app-using-flask-and-a0e3cc8ce9f6">Sixth Part of this Tutorial.</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*IDGmnmHe_Wj78xcP" /><figcaption>Photo by <a href="https://unsplash.com/@peet818?utm_source=medium&amp;utm_medium=referral">Pete Pedroza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Final Words</h3><p>Thanks for reading this post, we would love to hear your feedback. Feel free to Comment any Issues.<br>Give us a clap if you enjoyed it:) . Follow us to get our Latest Articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=799ffd367067" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/beginner-to-advance-web-scraping-guide-in-python-799ffd367067">Beginner to Advance : Web Scraping Guide in Python.</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>