python을 사용하여 whatsApp에서 채팅
파이썬을 사용하여 whatsapp에서 친구에게 메시지를 보내는 방법.
내 기사 중 일부를 읽었다면 배웠을 것입니다. python을 사용하여 whatsapp에 메시지를 보내고 싶지 않습니까? 그리고 누가 그것을 원하지 않습니까? 페이스북과 같은 간단한 방법이 있습니다.
많은 시간을 낭비하지 않고 수업에 들어갑시다.
먼저 아래 라이브러리를 설치해야 합니다.
이미 언급된 두 개의 라이브러리가 있다면 귀찮게 하지 마십시오.
위의 두 라이브러리를 설치한 후 코드 작성을 시작할 수 있습니다.
Facebook에서 친구에게 메시지를 보내는 방법에 대한 내 기사를 읽었다면 바로 가십시오.
코드에 복사하고 그렇지 않으면 다음 분석을 읽으십시오.
코드로 이동하기 전에 프로그램에서 사용할 일부 기능에 대한 분석을 제공하겠습니다.
작업에 대한 기타 요구 사항
휴대전화로 스캔하는 방법
이전에 whatsapp 채팅을 하기 위해 랩톱을 사용하지 않은 경우 브라우저에 whatsapp 웹이 로드되어 있을 때 휴대폰으로 스캔하기가 약간 어려울 수 있으므로 아래 단계를 따르십시오.
### 일부 기능 필요
find_element_by_xpath()
: 셀레늄 모듈에서 제공하는 기능css 선택기로 요소를 찾으려면.
send_keys()
: 우리가 사용하는 상자에 데이터나 텍스트를 쓰기 위해 셀레늄 모듈에서 제공하는 기능webdriver.Chrome()
: 크롬의 새 창을 여는 기능get()
: Facebook 웹사이트를 여는 데 사용할 기능quit()
: 완료되면 브라우저를 닫는 기능입니다. sleep()
: 스크립트 실행을 몇 초 동안 지연시키는 기능입니다. input()
및 str
: 프롬프트를 표시하고 문자열로 변환하는 Python 함수입니다. 당신은 전에 이것들에 익숙해 졌음에 틀림 없습니다. 가져오기에 필요한 모듈 및 중요 데이터
우리는 lib에서 다음을 가져와야 했습니다.
또한 친구 이름과 메시지를 제공해야 합니다.
코드는 다음과 같습니다.
from selenium import webdriver
from time import sleep
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(ChromeDriverManager().install())
# to chromedriver in your computer
message=str(input('enter your message')) # to get the message
driver.get("https://web.whatsapp.com/") #to open the whatsapp
sleep(39)
# here we need to scan with our phone
driver.find_element_by_xpath('//span[@title="Your friendName"][@dir="auto"]').click()# change that 'Your friendName to your own friend Name as it is written on your phone contact.
driver.find_element_by_xpath('//div[@dir="ltr"][@data-tab="6"][@spellcheck="true"]').send_keys(message, Keys.ENTER)
quit()
메시지가 전송되는 것을 보려면 몇 분 정도 기다리십시오. 재미있으셨나요? 그것은 Selenium의 힘의 일부일뿐입니다.
이것의 아름다운 부분은 루프를 사용하여 메시지를 반복하면서 긴 텍스트를 작성할 수 있다는 것입니다.
다른 재미있는 부분을 수행하십시오. 다음 코드를 확인해 봅시다.
예시
from selenium import webdriver
from time import sleep
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(ChromeDriverManager().install())
# to chromedriver in your computer
message=str(input('enter your message')) # to get the message
driver.get("https://web.whatsapp.com/") #to open the whatsapp
sleep(39)
# here we need to scan with our phone
driver.find_element_by_xpath('//span[@title="frndName"][@dir="auto"]').click()#your friend name to substitute that frndName
for msg in mess:
driver.find_element_by_xpath('//div[@dir="ltr"][@data-tab="6"][@spellcheck="true"]').send_keys(msg, Keys.ENTER)
quit()
# This is where I entered the the message and Did click Enter
메시지가 어떻게 생겼는지 보셨나요? 한 문자씩 메시지를 보냅니다. 메시지에 대한 루프를 작성하고 원하는 방식으로 메시지를 조작하십시오. 원하는 경우 빈 메시지를 보낼 수도 있습니다.
코딩을 즐기십시오! 우리가 논의할 다음 강의에서 뵙겠습니다. 아래에 좋아요와 댓글을 남겨주세요.
Reference
이 문제에 관하여(python을 사용하여 whatsApp에서 채팅), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://dev.to/maxwizardth/chat-on-whatsapp-using-python-5e9l텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)