Data entry is a repetitive and time-consuming task. Python provides powerful tools to automate data entry, reducing errors and saving time.
What Can Be Automated?
Filling out web forms
Entering data into Excel/Google Sheets
Populating databases
Submitting online applications
Automating form submissions
1. Setting Up the Environment
Before automating, install necessary libraries:
pip install selenium openpyxl pandas pyautogui
Modules Used:
selenium
→ Automate web formspyautogui
→ Simulate keyboard and mouse actionsopenpyxl
&pandas
→ Handle Excel data
2. Automating Data Entry in Web Forms
Filling Out an Online Form with Selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
# Open browser
driver = webdriver.Chrome()
# Go to form URL
driver.get("https://example.com/form")
# Fill in text fields
driver.find_element(By.NAME, "name").send_keys("John Doe")
driver.find_element(By.NAME, "email").send_keys("john.doe@example.com")
# Select a dropdown option
driver.find_element(By.NAME, "gender").send_keys("Male")
# Submit the form
driver.find_element(By.NAME, "submit").click()
# Close browser
time.sleep(2)
driver.quit()
Now forms can be filled automatically!
3. Automating Data Entry in Excel
Writing Data to an Excel File
from openpyxl import Workbook
wb = Workbook()
ws = wb.active
ws.append(["Name", "Email", "Age"])
ws.append(["Alice", "alice@example.com", 25])
ws.append(["Bob", "bob@example.com", 30])
wb.save("data.xlsx")
print("Data entered successfully!")
Now Excel data is automatically populated!
4. Automating Data Entry into Google Sheets
Using Google Sheets API to Insert Data
import gspread
from oauth2client.service_account import ServiceAccountCredentials
# Google Sheets API setup
scope = ["https://spreadsheets.google.com/feeds", "https://www.googleapis.com/auth/drive"]
creds = ServiceAccountCredentials.from_json_keyfile_name("credentials.json", scope)
client = gspread.authorize(creds)
# Open sheet
sheet = client.open("MySheet").sheet1
# Insert data
sheet.append_row(["John", "john@example.com", 28])
print("Data added to Google Sheets!")
Now Google Sheets is updated automatically!
5. Automating Database Entry
Inserting Data into a MySQL Database
import mysql.connector
conn = mysql.connector.connect(host="localhost", user="root", password="password", database="mydb")
cursor = conn.cursor()
cursor.execute("INSERT INTO users (name, email, age) VALUES (%s, %s, %s)", ("Alice", "alice@example.com", 25))
conn.commit()
cursor.close()
conn.close()
print("Data inserted into the database!")
Now database entries are automated!
6. Automating Keyboard Input with PyAutoGUI
Typing Text Automatically
import pyautogui
import time
time.sleep(3) # Give time to click on the input field
pyautogui.write("Hello, this is automated typing!", interval=0.1)
Now text is typed automatically!
7. Automating Bulk Form Submission
Reading Data from Excel and Submitting a Web Form
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
# Load Excel Data
data = pd.read_excel("data.xlsx")
driver = webdriver.Chrome()
driver.get("https://example.com/form")
for _, row in data.iterrows():
driver.find_element(By.NAME, "name").send_keys(row["Name"])
driver.find_element(By.NAME, "email").send_keys(row["Email"])
driver.find_element(By.NAME, "submit").click()
driver.quit()
print("Bulk data entry completed!")
Now bulk form submissions are automated!
8. Scheduling Data Entry Tasks
Run the script automatically at a specific time
import schedule
import time
def enter_data():
print("Running data entry script...")
# Call data entry function here
schedule.every().day.at("09:00").do(enter_data)
while True:
schedule.run_pending()
time.sleep(60)
Now data entry runs on schedule!