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.
Automate file and folder operations using Python’s standard libraries.
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")
Automate sending emails using Python.
smtplibemail.messageimport 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()
Web scraping extracts data from websites automatically.
requests → Fetch webpageBeautifulSoup → Parse HTMLpip install requests beautifulsoup4
import requests
from bs4 import BeautifulSoup
response = requests.get("https://example.com")
soup = BeautifulSoup(response.text, "html.parser")
print(soup.title.text)
for link in soup.find_all("a"):
print(link.get("href"))
Selenium automates browser-based interactions like clicking, filling forms, and login automation.
pip install selenium
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()
driver.find_element(By.NAME, "username").send_keys("admin")
driver.find_element(By.NAME, "password").send_keys("1234")
Schedule Python scripts to run automatically at fixed intervals.
schedule Librarypip install schedule
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)
Automate Excel file creation and manipulation.
openpyxlpip install openpyxl
from openpyxl import Workbook
wb = Workbook()
sheet = wb.active
sheet["A1"] = "Name"
sheet["B1"] = "Score"
sheet.append(["Prakash", 90])
wb.save("results.xlsx")
from openpyxl import load_workbook
wb = load_workbook("results.xlsx")
sheet = wb.active
print(sheet["A2"].value)
Create, read, and manipulate PDF files.
PyPDF2reportlabpip install PyPDF2 reportlab
from PyPDF2 import PdfReader
reader = PdfReader("sample.pdf")
print(reader.pages[0].extract_text())
from reportlab.pdfgen import canvas
c = canvas.Canvas("report.pdf")
c.drawString(100, 750, "Automation Report")
c.save()