栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python whatup 自动化

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python whatup 自动化

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")

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/839948.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号