368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Harshit Sidhwa
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # WhatsApp Bot
2 |
3 | This is a simple Web WhatsApp Bot developed in python using Selenium.
4 | Selenium is used mainly for automating web applications for testing purposes, but is certainly not limited to just that. Boring web-based administration tasks can (and should!) be automated as well.
5 |
6 | Selenium has the support of some of the largest browser vendors who have taken (or are taking) steps to make Selenium a native part of their browser. It is also the core technology in countless other browser automation tools, APIs and frameworks.
7 |
8 | - Send messages to family, friends and contacts automatically
9 | - Send specific message at specified time for all choosen contacts
10 | - Send the message in group also
11 |
12 | # Features!
13 |
14 | - Send a specific message to a particular contact at any time of the day
15 | - One can send a single message to multiple contacts over a specific time
16 | - Multiple messages to multiple contacts
17 | - It offers a delay so that WhatsApp can detect your are sending a URL and show its pop-up description.
18 | - It can search a contact from the list if the contact isn't present in the recent chats
19 | - Save the contact name, number in a xls file and save it in the same directory.
20 | - Change the message along with time in the whatsapp.py
21 | - You can add multiple messages
22 | - The Script can also search for the contact in the new chat list and then send message if the contact is not found in the recent chat list.
23 |
24 | ### Requirements
25 |
26 | * [Python 3+](https://www.python.org/download/releases/3.0/?) - Pyhton 3.6+ verion
27 | * [Selenium](https://github.com/SeleniumHQ/selenium) - Selenium for web automation
28 | * [openpyxl](https://pypi.org/project/openpyxl/) - To read xls files
29 |
30 | ### Installation
31 |
32 | Step 1: Install Selenium
33 | ```sh
34 | $ pip3 install selenium
35 | ```
36 |
37 | Step 2: Selenium requires a driver to interface with the chosen browser.
38 | > For [Click for Chrome](https://sites.google.com/a/chromium.org/chromedriver/downloads)
39 | > For [Click for FireFox](https://github.com/mozilla/geckodriver/releases)
40 | > For [Click for safari](https://webkit.org/blog/6900/webdriver-support-in-safari-10)
41 |
42 | Step 3: Extract the downloaded driver onto a folder
43 |
44 | Step 4: Set path variable to the environment. Paste this command to the terminal
45 | ```sh
46 | $ export PATH=$PATH:/home/path/to/the/driver/folder/
47 | Eg: $ export PATH=$PATH:/home/harshit/Desktop/WhatsAppBot
48 | ```
49 | Step 5: run whatsapp.py using Python3
50 | ```sh
51 | $ python3 whatsapp.py
52 | ```
53 | Step 6: When the browser is opened web.whatsapp.com will be opened and will ask to scan a QR code when you it first time
54 |
55 | Step 7: After Scanning the QR code, you will be asked to press Enter Key in the terminal.
56 |
57 | ### Note
58 |
59 | You can also add Names of the contact you want to send message in the Contacts.txt file.
60 | The contact name should match exactly with the name saved in your contacts.
61 |
--------------------------------------------------------------------------------
/contacts.xlsx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/harshitsidhwa/WhatsApp-bot-selenium/94a85569181a148dc158e5114a7197b033a32814/contacts.xlsx
--------------------------------------------------------------------------------
/whatsapp.py:
--------------------------------------------------------------------------------
1 | # Note: For proper working of this Script Good and Uninterepted Internet Connection is Required
2 | # Keep all contacts unique
3 | # Can save contact with their phone Number
4 |
5 | # Import required packages
6 | from selenium import webdriver
7 | from selenium.webdriver.support.ui import WebDriverWait
8 | from selenium.webdriver.support import expected_conditions as EC
9 | from selenium.webdriver.common.keys import Keys
10 | from selenium.webdriver.common.by import By
11 | import datetime
12 | import time
13 | import openpyxl as excel
14 |
15 | # function to read contacts from a text file
16 | def readContacts(fileName):
17 | lst = []
18 | file = excel.load_workbook(fileName)
19 | sheet = file.active
20 | firstCol = sheet['A']
21 | for cell in range(len(firstCol)):
22 | contact = str(firstCol[cell].value)
23 | contact = "\"" + contact + "\""
24 | lst.append(contact)
25 | return lst
26 |
27 | # Target Contacts, keep them in double colons
28 | # Not tested on Broadcast
29 | targets = readContacts("contacts.xlsx")
30 |
31 | # can comment out below line
32 | print(targets)
33 |
34 | # Driver to open a browser
35 | driver = webdriver.Firefox()
36 |
37 | #link to open a site
38 | driver.get("https://web.whatsapp.com/")
39 |
40 | # 10 sec wait time to load, if good internet connection is not good then increase the time
41 | # units in seconds
42 | # note this time is being used below also
43 | wait = WebDriverWait(driver, 10)
44 | wait5 = WebDriverWait(driver, 5)
45 | input("Scan the QR code and then press Enter")
46 |
47 | # Message to send list
48 | # 1st Parameter: Hours in 0-23
49 | # 2nd Parameter: Minutes
50 | # 3rd Parameter: Seconds (Keep it Zero)
51 | # 4th Parameter: Message to send at a particular time
52 | # Put '\n' at the end of the message, it is identified as Enter Key
53 | # Else uncomment Keys.Enter in the last step if you dont want to use '\n'
54 | # Keep a nice gap between successive messages
55 | # Use Keys.SHIFT + Keys.ENTER to give a new line effect in your Message
56 | msgToSend = [
57 | [12, 32, 0, "Hello! This is test Msg. Please Ignore." + Keys.SHIFT + Keys.ENTER + "http://bit.ly/mogjm05"]
58 | ]
59 |
60 | # Count variable to identify the number of messages to be sent
61 | count = 0
62 | while count