This Python script utilizes the pyautogui
library for automating interactions with the Microsoft Edge browser and a web form. Here's a breakdown of what the code does:
- Imports the necessary libraries:
pyautogui
andtime
. - Sets a pause of 1 second between each PyAutoGUI action.
- Presses the Windows key to open the Start menu.
- Types "microsoft edge" into the search bar and presses Enter to open Microsoft Edge.
- Waits for 5 seconds to ensure the browser has opened.
- Defines a variable
link
containing a file path to a local HTML file.(its necessary to be your own file path) - Enters the link into the browser's address bar and presses Enter.
- Waits for 8 seconds for the page to load.
- Imports the
pandas
library for reading CSV files. - Reads data from a CSV file named "produtos.csv" into a pandas DataFrame.
- Iterates over each row of the DataFrame.
- Performs the following actions for each row:
- Clicks on a specific position on the screen (assuming it's a specific form input field).
- Writes data from the DataFrame into the form fields.
- Scrolls down the page.
- The script finishes its execution.
This is a Python code example that utilizes the PyAutoGUI library to automate the filling of a web form using the Microsoft Edge browser. The goal is to fill form fields with data stored in a CSV file.
- Opens the Microsoft Edge browser.
- Loads a specific web page.
- Reads data from a CSV file.
- Fills form fields with data from the CSV file.
- Submits the form automatically.
-
Install the necessary libraries:
-
Install Python 3.x: Download Python
-
Install the PyAutoGUI and pandas libraries via pip:
pip install pyautogui pandas
-
-
Run the Python script.
-
Make sure to adjust the file paths as needed:
- Update the HTML file path in the
link
variable. - Ensure that the CSV file with the data is correctly specified.
- Update the HTML file path in the
- Opens the Microsoft Edge browser.
- Loads a specific web page.
- Reads data from a CSV file.
- Fills form fields with data from the CSV file.
- Submits the form automatically.
- Python 3.x
- Installed Microsoft Edge browser (it can be any browser, since you replace with its name in the script)
- Access to the PyAutoGUI and pandas modules
- This script has been tested in a Windows environment.
- Adjustments may be necessary depending on the specific dimensions and layout of the web form.
- It's important to understand the risks of automation and ensure that the usage is ethical and legal.