About | Features | Technologies | Requirements | Execution | License | Author
This project consists of a Python script that automates sending messages to contacts on WhatsApp Web. The script uses the following libraries:
- pandas: to import the Excel file containing contacts and messages to be sent.
- selenium: to control the Chrome browser and interact with WhatsApp Web.
- urllib: to encode the message before sending.
The script was developed using Visual Studio Code with Python version 3.10.4.
The script works as follows:
- Imports an Excel file containing contacts and messages to be sent.
- Opens WhatsApp Web in the Chrome browser.
- Iterates through the Excel file, sending a message to each contact.
- The message is sent in the format: "Hi [name]! [message]".
- The script waits 12 seconds between each message to prevent WhatsApp from blocking the account.
The code is divided into two main parts:
- Importing an Excel File
- Automating Message Sending
The first part of the code imports an Excel file containing the contacts and messages to be sent. The file should have the following columns:
- Person: contact's name.
- Number: contact's phone number.
- Message: message to be sent.
The code uses the pandas library to import the Excel file. The following snippet demonstrates how to import the file:
contatos_df = pd.read_excel(r"arquivos/Enviar.xlsx")
The second part of the code automates the sending of messages to the contacts listed in the Excel file. The code functions as follows:
✔️ Feature 1: Opens WhatsApp Web in the Chrome browser.
✔️ Feature 2: Iterates through the Excel file, sending a message to each contact.
✔️ Feature 3: Sends the message in the format: "Hi [name]! [message]".\
The following snippet demonstrates how a message is sent to a contact:
pessoa = contatos_df.loc[i, "Pessoa"]
numero = contatos_df.loc[i, "Número"]
texto = urllib.parse.quote(f"Hi {pessoa}! {mensagem}")
link = f"https://web.whatsapp.com/send?phone={numero}&text={texto}&/n"
navegador.get(link)
while len(navegador.find_elements(By.ID, "pane-side")) < 1:
time.sleep(1)
time.sleep(1)
navegador.find_element(By.XPATH, '//*[@id="main"]/footer/div[1]/div/span[2]/div/div[2]/div[2]/button/span').click()
The following tools were used in this project:
Before starting 🏁, you need to have Git and Python installed.
# Clone the project
$ git clone https://github.com/gsoaresdz/automacao-mensagem.git
- This script was developed for educational purposes. It is not recommended to use the script for mass messaging to contacts who have not authorized receiving messages.
- The script can be modified to meet different needs. For example, you can change the time interval between message sending or add new functionalities.
This project is licensed under the MIT License. For more details, check the [LICENSE](LICENSE file.
Made with ❤️ by gsoaresdz