python whatup 自动化

python whatup 自动化,第1张

1. pywhatkit 打开默认浏览器 edge ,进行自动化 *** 作

import pywhatkit as send

import datetime

import pyautogui as pg



x = datetime.datetime.now()



min = x.strftime("%M")

hour = x.strftime("%H")

h = int(hour)

m = int(min)




phone = "+13566121846"

text = "bonsoir"



send.sendwhatmsg(phone,text,h,m+1)

pg.press("enter")

参考上面 git  源码

 


import os
from pyautogui import (
    ImageNotFoundException,
    click,
    hotkey,
    locateOnScreen,
    moveTo,
    press,
    size,
    typewrite,
)

WIDTH, HEIGHT = size()


def findtextbox() -> None:
    """click on text box"""
    dir_path = os.path.dirname(os.path.realpath(__file__))
    print(dir_path)
    location = locateOnScreen(f"{dir_path}\\pywhatkit_smile1.png")
    print(location)
    try:
        moveTo(location[0] + 150, location[1] + 5)
    except Exception:
        location = locateOnScreen(f"{dir_path}\\pywhatkit_smile.png")
        moveTo(location[0] + 150, location[1] + 5)
    click()


import time
import webbrowser as web
from datetime import datetime
from re import fullmatch
from urllib.parse import quote 
import pyautogui as pg
pg.FAILSAFE = False

def sendwhatmsg_instantly(
    phone_no: str,
    message: str,
    wait_time: int = 15,
    tab_close: bool = False,
    close_time: int = 3,
) -> None:
    """Send WhatsApp Message Instantly"""  
    web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")
    time.sleep(4)
    print("Waiting for message to be sent...")
    pg.click(WIDTH / 2, HEIGHT / 2)
    print(WIDTH, HEIGHT)
    findtextbox()
    pg.press("enter")

    
sendwhatmsg_instantly("+13526121846","123123123")

2. chromedriver 实现 需要 chromedriver.exe 打开 chrom浏览器


from selenium import webdriver
import time

class whatsappbot:
    def __init__(self):
        self.mensagem = "Olá estou testando o meu bot que fiz com pythom!"
        self.grupos = ["Grupo de teste"]
        options = webdriver.ChromeOptions()
        options.add_argument('lang=pt-br')
        self.driver = webdriver.Chrome(executable_path=r'chromedriver.exe')

    def EnviarMensagens(self):
        print('fjjbifakkb')
        self.driver.get('https://web.whatsapp.com')
        time.sleep(30)
        for grupo in self.grupos:
            grupo = self.driver.find_element_by_xpath(f"//span[@title='{grupo}']")
            time.sleep(3)
            grupo.click()
            chat_bot = self.driver.find_element_by_class_name('_13mgZ')
            time.sleep(3)
            chat_bot.click()
            chat_bot.send_keys(self.mensagem)
            botao_enviar = self.driver.find_element_by_xpath(f"//span[@data-icon='send']")
            time.sleep(3)
            botao_enviar.click()
            time.sleep(5)

bot = whatsappbot()
bot.EnviarMensagens()
print("Fim da execução")

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/790984.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-05
下一篇 2022-05-05

发表评论

登录后才能评论

评论列表(0条)

保存