无WebAPI与WebService时,如何访问编辑网站HTML并提交员工工时表?
Hey there, I get where you're coming from—web scraping is only for pulling data from sites, not pushing it into them. Let's dive into practical, actionable solutions you can use here:
1. Frontend Automation Tools (Simulate Human User Actions)
Tools like Selenium or Playwright let you script exactly what a human would do in a browser. You can write code to:
- Launch the employee portal's timesheet page
- Locate form fields (by ID, class, or XPath)
- Fill in hours, project codes, dates, and other required details
- Trigger the "Submit" button to save the entry
Here's a simplified example with Python + Selenium:
from selenium import webdriver from selenium.webdriver.common.by import By # Initialize browser session driver = webdriver.Chrome() driver.get("https://your-company-portal.com/timesheet") # Handle login first (if needed) driver.find_element(By.ID, "username").send_keys("your-username") driver.find_element(By.ID, "password").send_keys("your-password") driver.find_element(By.ID, "login-btn").click() # Fill timesheet form driver.find_element(By.ID, "daily-hours").send_keys("8") driver.find_element(By.ID, "project-id").send_keys("PROJ-456") driver.find_element(By.ID, "work-date").send_keys("2024-05-20") # Submit the entry driver.find_element(By.ID, "save-timesheet").click() driver.quit()
Just remember to account for dynamic elements, captchas, or multi-factor auth if your portal uses them.
2. Manually Replicate Form Submission Requests
Most portals use standard HTTP POST requests when you submit a form. You can reverse-engineer this process:
- Open your browser's DevTools (F12) and go to the Network tab
- Fill out a test timesheet entry manually and submit it
- Look for the POST request sent to the server (usually something like
/submit-timesheet) - Copy the request headers, form data, and required tokens (like CSRF tokens)
- Use tools like
curlor Python'srequestslibrary to send the same request programmatically
Example with curl:
curl -X POST "https://your-company-portal.com/submit-timesheet" \ -H "Content-Type: application/x-www-form-urlencoded" \ -H "Cookie: your-session-cookie" \ -d "hours=8&project_id=PROJ-456&date=2024-05-20&csrf_token=xyz789"
Pro tip: Test with dummy data first to avoid accidental duplicate submissions.
3. Browser Extension (User-Friendly for Non-Technical Teams)
If you need a solution that's easy for other employees to use, build a simple browser extension (Chrome/Firefox):
- The extension can inject a custom quick-fill panel into the portal's timesheet page
- When users click a button, the extension's JavaScript fills the existing form fields and triggers the submit event
- This integrates directly with the portal's workflow without requiring users to run scripts manually
4. Desktop Automation Tools (For Simple Repetitive Tasks)
For basic, routine timesheet entries, tools like AutoHotkey (Windows) or Automator (Mac) work well:
- Record a sequence of keystrokes and mouse clicks (e.g., open the portal, tab to the hours field, type "8", click submit)
- Save the sequence as a shortcut that can be run with a single keypress
- Ideal for daily/weekly entries that follow a consistent pattern
Critical Notes
- Always check your company's IT policies first—some organizations restrict automated form submissions to protect data integrity.
- Test all scripts/tools in a non-production environment to avoid messing up real timesheet data.
- Be mindful of rate limits or captchas that might block automated requests.
内容的提问来源于stack exchange,提问作者pooja sharma

