<?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 Anto Jeffry A on Medium]]></title>
        <description><![CDATA[Stories by Anto Jeffry A on Medium]]></description>
        <link>https://medium.com/@antojeffry08?source=rss-47cfcae9c613------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RG4tCS9Jv75Bq4DlvWqdNQ.jpeg</url>
            <title>Stories by Anto Jeffry A on Medium</title>
            <link>https://medium.com/@antojeffry08?source=rss-47cfcae9c613------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:23:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@antojeffry08/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[Automate multiple CSV files download using Python Web Scraping.]]></title>
            <link>https://antojeffry08.medium.com/automate-multiple-csv-files-download-using-python-web-scraping-d7a956dddddd?source=rss-47cfcae9c613------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7a956dddddd</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[web-scraping]]></category>
            <category><![CDATA[selenium-webdriver]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Anto Jeffry A]]></dc:creator>
            <pubDate>Thu, 27 Jul 2023 07:47:07 GMT</pubDate>
            <atom:updated>2023-07-27T08:26:55.890Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Imagine a website containing 100+ CSV files to download. Would you download it one by one manually?.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uMx83eFhdYZImy0dUuYrNA.png" /><figcaption><a href="https://www.scrapingbee.com/blog/web-scraping-101-with-python/">Source</a></figcaption></figure><p>To download more than 100 + CSV files manually is a real headache and time consuming. Why bother going through it when we can automate the process by a few lines of code.</p><p>If you want to learn more about web scraping or want to know the basics there are many blogs out there and youtube videos to master. But don’t worry, even if you are a absolute beginner, I guarantee that you will master how to automate CSV files download.</p><p><strong>Requirements:<br></strong>1. Python. (I use Jupyter notebook)<br>2. Installing the necessary libraries for web scarping and importing them.</p><pre>#installing libraries <br>pip install requests<br>pip install beautifulsoup4<br>pip install selenium<br>pip install webdriver-manager<br><br>#importing libraries<br>from selenium import webdriver<br>from webdriver_manager.chrome import ChromeDriverManager<br>from bs4 import BeautifulSoup<br>import requests<br>import os</pre><p>3. Web scraping isn’t always allowed. So, we have to check the html status response first in order to see if a website can be scraped.</p><pre>url=&quot;your_url_here&quot;<br><br>req=requests.get(url)<br>req<br><br>#or use the code below<br><br>req.status_codeut</pre><p><strong>If your output is more than 200. Then we can scrape the files.</strong></p><p><strong>Let’s get started…</strong></p><p>You can use the below website from which you can practice downloading large number of Excel files in a single go. The process and methods are exactly and literally the same like the one we are going to do here..</p><p><a href="https://data.gov.au/dataset/ds-qld-07d0dac2-71b3-470c-9e58-9fbbf83048a2/details?q=statistics">visitors_gov_data</a></p><p>But to make this web scraping hard, I am going to download multiple excel files from each year of the below website. The thing is each year content have the <strong>same URL link. </strong>So how to download every Excel file from each year?<strong>🤨</strong></p><p><a href="https://www.rbi.org.in/Scripts/ATMView.aspx">Reserve Bank of India - Bankwise ATM/POS/Card Statistics</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BHGMJfhyFYPkQ0B9pF5EFg.png" /><figcaption>RBI website</figcaption></figure><p>Now as you can see from the website each year have the <strong>same website url</strong>.</p><p>To tackle this, we have to use <strong>selenium </strong>and <strong>ChromeDriver. </strong>let’s go</p><p>To install ChromeDriver</p><ol><li>Get your Chrome version from copying the below link and paste it in a new tab url section<br><strong>chrome://version/</strong></li><li>To your version of chrome, download the respective ChromeDriver <a href="https://sites.google.com/chromium.org/driver/downloads?authuser=0"><strong>here</strong></a>.</li></ol><p>After installing ChromeDriver, get the chrome’s test page get running</p><pre>url=&quot;https://www.rbi.org.in/Scripts/ATMView.aspx&quot;<br><br>chrome_driver_path = &#39;your_downloaded_chromedriver.exe_path&#39;  <br><br>webdriver.chrome.service.Service.executable_path = chrome_driver_path<br><br>driver = webdriver.Chrome()<br>driver.get(url)</pre><p>This is the important step. Here when we run the code. A google test chrome appears with the rbi website.</p><p><strong>Year navigation step</strong></p><p>Here navigate to any year from which you want the excel files to be downloaded. <strong>Remember the year page you are choosing here will be the only Excel files which will be downloaded. (</strong>Example: If you choose 2022, only the 2022 Excel files will be downloaded)</p><p>After selecting the year you want to download. let’s close the driver and scrape.</p><pre>html= driver.page_source<br>driver.close()<br><br>soup=BeautifulSoup(html)<br>soup.find_all(&quot;a&quot;)<br></pre><p>The &lt;a&gt; tags in the html are the ones which contain hyperlinks for downloads. However, when we run the code, we will see a lot of unwanted hyperlinks.</p><p>So to get only our Excel files we are going to do a little inspection🧐…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o38WfBA-WrdrfoeoClQKZQ.png" /></figure><p>When we right-click the Excel file download button and click inspect on the RBI website, We can see the &lt;a&gt; tag which contains our desired Excel file.</p><ol><li>Like this, when we inspect every Excel download button, we can see that all the <strong>“href” </strong>links start with the same url path “<a href="https://rbidocs.rbi.org.in/rdocs/ATM/DOCs/"><strong>https://rbidocs.rbi.org.in/rdocs/ATM/DOCs/</strong></a>&quot; and then after that, all the files have different paths.</li><li>We also know that all the excel files end with <strong>.XLSX </strong>extension as the files are excel.</li></ol><p>Let’s use these two conditions.</p><p>Below, list comprehension method is used to shorten our code and also to make things simple rather than using many loops. So, here we are searching for all the <strong>“href”</strong> links with <strong>&lt;a&gt; tag </strong>that contains the first part of the URL file path and files ending with<strong> .XLSX </strong>(If it is a CSV file, use <strong>.CSV)</strong></p><pre>url_start=&quot;https://rbidocs.rbi.org.in/rdocs/ATM/DOCs/&quot;<br>download_links=[link[&quot;href&quot;] for link in soup.find_all(&quot;a&quot;) if link.has_attr(&quot;href&quot;) and link[&quot;href&quot;].startswith(url_start)]<br>download_links</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2j1nPNX0igOFO-4aXzd5ow.png" /></figure><p>Great…now that all our Excel files are here. Let’s rename them for better identification and download them.</p><pre>name=[&quot;Dec_2022&quot;, &quot;Nov_2022&quot;,&quot;Oct_2022&quot;, &quot;Sept_2022&quot;, &quot;Aug_2022&quot;, &quot;Jul_2022&quot;, &quot;Jun_2022&quot;, &quot;May_2022&quot;, &quot;Apr_2022&quot;,<br>     &quot;Mar_2022&quot;, &quot;Feb_2022&quot;, &quot;Jan_2022&quot;]<br><br><br>for link, filename in zip(download_links, name):<br>    response = requests.get(link)<br>    with open(filename + &quot;.xlsx&quot;, &quot;wb&quot;) as f:<br>        f.write(response.content)        </pre><p>Yaaaay….! <br>All the excel files have been downloaded. Check them by running the below code</p><pre>os.listdir()</pre><p>Now, use the <strong>Navigation step </strong>again if you want the files from other years. Remember you don’t have to do this step again if you have all the Excel files in the website like <a href="https://data.gov.au/dataset/ds-qld-07d0dac2-71b3-470c-9e58-9fbbf83048a2/details?q=statistics">visitors_gov_data</a>.</p><p>If you stayed till the end.. <br><strong>Congratulations for learning🎉🎉.</strong></p><p><strong>Thank you for reading… Have a great day😊…</strong></p><p>From this <strong>(uncleaned dataset)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qy8Ff6khLYdBVloKHFUmoA.jpeg" /></figure><p>to this <strong>(cleaned dataset)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lyh853seD9pqiShI-MsPFA.jpeg" /></figure><p>to this <strong>(Microsoft PowerBi dashboard)</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*yWUO26brBK6GzmOhjk9Wyg.png" /><figcaption>Author: Anto Jeffry A</figcaption></figure><p>Would you guys like to know more about my project. What do you think about this blog and my dashboard. Let me know in the comment section or let’s connect via LinkedIn😊.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7a956dddddd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>