Development

Python | Membuat Bot Whatsapp dengan Selenium

Pinterest LinkedIn Tumblr

Bot digunakan untuk melakukan sesuatu hal secara otomatis. Dengan sekali perintah maka bot akan melakukan pekerjaannya. Kali ini kita akan belajar dasar membuat bot whatsapp web menggunakan python.

Alat dan bahan yang harus disiapkan :

  1. Install python
    Untuk install python bisa baca disini
  2. Install PIP Selenium
    Jangan lupa install selenium bisa dibaca disini
  3. Download driver browser
    Untuk download browser bisa click disini

Langkah pembuatannya :

Pertama copy code dibawah ini


#Import webdriver dari Selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

#Masukkan driver Chrome
driver = webdriver.Chrome('chromedriver')
driver.maximize_window()
#Menuju alamat yang dituju
driver.get("http://web.whatsapp.com/")

#Untuk meminta jumlah akun yang akan dikirim pesan
a = int(input('Berapa akun : '))
b = []

#Perulangan sesuai jumlah akun yang dimaksukan
for i in range(a):
    c = str(1+i)
    print('User yang ke-'+c)
    #Memaksukan nama user
    name = input("Masukkan User :")
    #Menyimpannya pada variable b
    b.append(name)

#Masukkan pesan yang ingin dikirim
msg = input('Masukkan Pesan :')
#Untuk jeda
input('Tekan Enter')

#Perulangan sesuai dengan user yang telah dimasukkan
#Dan variable b dimasukkan ke x
for x in b :
    #Mencari  dan mencari title lalu menggantinya dengan isi variable x
    user = driver.find_element_by_xpath('//span[@title = "{}"]'.format(x))
    #Lalu click untuk masuk ke chat user tersebut
    user.click()
    #Mencari element class '_13mgZ' ini adalah element text box untuk membuat pesan
    msg_box = driver.find_element_by_class_name('_13mgZ')
    #Memasukkan pesan yang udah di buat pada variable msg
    msg_box.send_keys(msg)
    #mencari element class '_3M-N-' ini adalah element button untuk send pesan
    button = driver.find_element_by_class_name('_3M-N-')
    #click untuk mengirim pesan
    button.click()
    #Sebagai info bahwa perintah udah dilaksanakan
    print('Pesan ke ' + x + ' Sudah terkirim')

Dalam code diatas kamu dapat mengganti browser sesuai dengan yang kamu sukai di https://www.seleniumhq.org/download/

Begitulah cara membuat bot whatsapp web. Sekian terima kasih! Salam ora umum!

Author

13 Comments

  1. untuk langkah selanjutnya gimana?
    setelah kita copy codenya?
    mohon bantuaannya min

    • arga Reply

      1. Buka terminal (linux) atau cmd (windows)
      2. ketik “python nama_file_python.py”
      3. Enter

      • Oke Terima kasih,
        Sudah Bisa.

        Request Min,
        untuk Pengiriman Pesannya langsung ambil Kontak dari Excel kemudian untuk Pesan yang ingin di kirim juga langsung tulis di code, tidak perlu dari CMD lagi,

        Terima kasih Min

  2. I would like to salute you for the extreem lengths you have put in creating this website. Incredibly your superior knowledge and detailed subjects has encouraged me to have to begin my own forum. werid Check this web site I just created for onion seo in flagstaff my web page, flagstaff seo company. Well, want to chat and start some fascinating topics with all of you a lot. Thank you – contributing niche informations. Your vast amount of knowledge is totally inspiring and will help my friends and I in my hobbies. I am so shocked by the expertise knowledge that everybody on this web site. It is obvious how nicely everybody has masters this subject. I bookmarked this forum and will come back for extra posts. You my pals are the one of a kind savants. I serendipitously came across the info that we had previously found but forgot everywhere and just couldn’t come across. What a helpful web-blog.

  3. RandallVeinY Reply

    All of us here are excited to have found such a nice web page, it is toally the stuff my friend and I always looking for. The up to date info on this website is definitely appreciated and is going to assist my friends and I all the time. Seems like everybody here gathered a significant amount ofamazing of noumena pertaining to the things I am always studying and other pages and bases of knowledge really shows it. I am not usually on the web when I am busy though when my group have some time we are always hunting for this type of knowledge or stuff closely concerning it. I have a few of my relatives that have picked up a liking in this due to all that I’ve learned about the subject and they’re definitely to be visiting this forum because it’s such an super learning place. I am also fascinated in government issues and coping with the constant twists and turns in politics and equally sedarching for new handicapping experts to satisfy making residual income. I wanted to share with you my business which is a trust source of moneyeye shadow and in bath bomb dye I have some other business that do well on Amazon. too. Feel Free to send me a message if you want to know more.

  4. D:\py_project>python WA1.py

    DevTools listening on ws://127.0.0.1:57524/devtools/browser/51ddf0c9-9020-40ed-9
    317-cfae62f7cfe9
    [0220/100327.751:ERROR:gl_surface_egl.cc(690)] EGL Driver message (Error) eglQue
    ryDeviceAttribEXT: Bad attribute.
    [0220/100327.752:ERROR:gl_surface_egl.cc(690)] EGL Driver message (Error) eglQue
    ryDeviceAttribEXT: Bad attribute.
    [0220/100327.752:ERROR:gl_surface_egl.cc(690)] EGL Driver message (Error) eglQue
    ryDeviceAttribEXT: Bad attribute.
    [0220/100327.753:ERROR:gl_surface_egl.cc(690)] EGL Driver message (Error) eglQue
    ryDeviceAttribEXT: Bad attribute.
    [0220/100327.889:ERROR:gl_surface_egl.cc(690)] EGL Driver message (Error) eglQue
    ryDeviceAttribEXT: Bad attribute.
    [0220/100330.171:ERROR:gl_surface_egl.cc(690)] EGL Driver message (Error) eglQue
    ryDeviceAttribEXT: Bad attribute.
    [0220/100330.437:ERROR:gl_surface_egl.cc(690)] EGL Driver message (Error) eglQue
    ryDeviceAttribEXT: Bad attribute.
    Berapa akun : 2
    User yang ke-1
    Masukkan User :628xxx
    User yang ke-2
    Masukkan User :628xxx
    Masukkan Pesan :Uji coba WA
    Tekan Enter
    Traceback (most recent call last):
    File “WA1.py”, line 33, in
    user = driver.find_element_by_xpath(‘//span[@title = “{}”]’.format(x))
    File “D:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py”, lin
    e 394, in find_element_by_xpath
    return self.find_element(by=By.XPATH, value=xpath)
    File “D:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py”, lin
    e 976, in find_element
    return self.execute(Command.FIND_ELEMENT, {
    File “D:\python\lib\site-packages\selenium\webdriver\remote\webdriver.py”, lin
    e 321, in execute
    self.error_handler.check_response(response)
    File “D:\python\lib\site-packages\selenium\webdriver\remote\errorhandler.py”,
    line 242, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.NoSuchElementException: Message: no such element: Una
    ble to locate element: {“method”:”xpath”,”selector”:”//span[@title = “628xxx”]”}
    (Session info: chrome=80.0.3987.116)

    Mohon solusinya?

  5. RandallVeinY Reply

    I am lucky to have discovered the website, this is toally esoterics my friends from work and I continually searching for. The information on the web site is very needed and is going to help my family and friends significantly. Appears like everyone gathered tons ofunusually deep amount of noumena concerning the sorts of stuff I am interested in and the other hyper links and info really shows it. I’m usually not on the internet during the day though when my group get a chance I am more often than not hunting for this kind of knowledge and others closely concerning it. I have some of my family members that have also assumed attatchment in this due to all that I have learned of it and they will probably to visit this site because it is such an excellent discovery. I’m also delving into in government issues and coping with the new twists and turns in elections as well as looking for other handicapping services to satisfy making residual income. I just started a company that is a knowledgable bread and Butteressential oils and in colorant I have some other business that do well on Google. also. Feel Free to send me a message if you want to learned more.

  6. Diese shoulds die beste Sammlung von Website bloggen ich je herausgefunden . Laure Alexandr Peirce

  7. Bonjour, ton blogue est très réussi! Je te dis bravo! C’est du beau boulot! 🙂 Leone Rainer Steinke

Write A Comment