Log In

Don't have an account? Sign up now

Lost Password?

Sign Up

Prev Next

MODULE 14: Automation & Scripting

Python is one of the best languages for automation. It allows you to automate repetitive tasks like file handling, emails, web data extraction, browser actions, reports, and scheduling.

1. Automating Files & Folders

Brief

Automate file and folder operations using Python’s standard libraries.

Common Operations

  • Create, delete, rename files
  • Move and copy folders
  • Search files

Example: File & Folder Automation

import os
import shutil

os.mkdir("reports")
open("reports/data.txt", "w").write("Automation Report")

shutil.copy("reports/data.txt", "backup.txt")
os.rename("backup.txt", "final_backup.txt")

Real-World Use

  • Daily report generation
  • Backup scripts
  • Log cleanup automation

2. Email Automation

Brief

Automate sending emails using Python.


Libraries Used

  • smtplib
  • email.message

Example: Send Email

import smtplib
from email.message import EmailMessage

msg = EmailMessage()
msg.set_content("This is an automated email")
msg["Subject"] = "Automation Test"
msg["From"] = "youremail@gmail.com"
msg["To"] = "receiver@gmail.com"

server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login("youremail@gmail.com", "yourpassword")
server.send_message(msg)
server.quit()

Real-World Use

  • Job alerts
  • System notifications
  • Marketing campaigns

3. Web Scraping (BeautifulSoup & Requests)

Brief

Web scraping extracts data from websites automatically.


Libraries

  • requests → Fetch webpage
  • BeautifulSoup → Parse HTML

Install Libraries

pip install requests beautifulsoup4

Example: Scrape Website Title

import requests
from bs4 import BeautifulSoup

response = requests.get("https://example.com")
soup = BeautifulSoup(response.text, "html.parser")

print(soup.title.text)

Extract Multiple Elements

for link in soup.find_all("a"):
    print(link.get("href"))

Real-World Use

  • Job listings scraping (like CommonJobs)
  • Price monitoring
  • News aggregation

4. Selenium Automation

Brief

Selenium automates browser-based interactions like clicking, filling forms, and login automation.


Install Selenium

pip install selenium

Basic Selenium Example

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://example.com")

button = driver.find_element(By.TAG_NAME, "a")
button.click()

Form Automation

driver.find_element(By.NAME, "username").send_keys("admin")
driver.find_element(By.NAME, "password").send_keys("1234")

Real-World Use

  • Form submission
  • Automated testing
  • Website monitoring

5. Task Scheduling

Brief

Schedule Python scripts to run automatically at fixed intervals.


Using schedule Library

pip install schedule

Example: Daily Task

import schedule
import time

def job():
    print("Task executed")

schedule.every().day.at("10:00").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)

OS-Level Scheduling

  • Windows → Task Scheduler
  • Linux/Mac → Cron Jobs

6. Excel Automation

Brief

Automate Excel file creation and manipulation.


Library Used

  • openpyxl

Install

pip install openpyxl

Example: Write Excel File

from openpyxl import Workbook

wb = Workbook()
sheet = wb.active
sheet["A1"] = "Name"
sheet["B1"] = "Score"
sheet.append(["Prakash", 90])

wb.save("results.xlsx")

Read Excel

from openpyxl import load_workbook

wb = load_workbook("results.xlsx")
sheet = wb.active
print(sheet["A2"].value)

Real-World Use

  • Reports
  • HR data processing
  • Financial sheets

7. PDF Automation

Brief

Create, read, and manipulate PDF files.


Libraries

  • PyPDF2
  • reportlab

Install

pip install PyPDF2 reportlab

Read PDF

from PyPDF2 import PdfReader

reader = PdfReader("sample.pdf")
print(reader.pages[0].extract_text())

Create PDF

from reportlab.pdfgen import canvas

c = canvas.Canvas("report.pdf")
c.drawString(100, 750, "Automation Report")
c.save()

Leave a Comment

    🚀 Join Common Jobs Pro — Referrals & Profile Visibility Join Now ×
    🔥