Python 上的“pywhatskit”不发送消息

问题描述 投票:0回答:9

使用 pywhatkit 模块,您可以在 WhatsApp 上发送消息,

我使用的脚本:

import pywhatkit as w

w.sendwhatmsg("xxxxxxxx", " this is a generated msg",9,26)

x 是数字

问题是,它所做的只是将消息加载到 WhatsApp 的文本框中,而不发送。我是不是错过了什么?

python message whatsapp send
9个回答
5
投票
import pywhatkit as w
import time
import pyautogui
import keyboard as k
w.sendwhatmsg("your number", 'hi', 8, 38)
pyautogui.click(1050, 950)
time.sleep(2)
k.press_and_release('enter')

通过 pyautogui.click 你可以将光标调整到消息框,然后它会点击它 然后用键盘点击输入就可以了,就这么简单


5
投票

我刚刚遇到了同样的问题,我使用以下命令卸载并再次安装了 pywhatkit:

pip uninstall pywhatkit
pip install pywhatkit

我知道这个问题很老了,希望它能帮助有同样问题的人


4
投票

您必须将等待时间增加到30秒以上,这通常是由于网速较慢而发生的。像这样写:

import pywhatkit as py
py.sendwhatmsg("+91xxxxxxxxxx", "hello", 13, 12, 32)

1
投票

这似乎是 Pywhatkit 中的一个错误:https://github.com/Ankit404butfound/PyWhatKit/issues/20


1
投票

该模块当前仅支持 1 个屏幕,如果您使用多个屏幕,并且新的 Whatsapp 网站当前在与代码运行的单独窗口上打开,则会出现该错误。这是一个已知问题,因此,如果您要使用多个屏幕(谁不会),请确保您选择的编辑器(即:google chrome 和 Visual Studio)位于同一屏幕上。


1
投票

问题是pywhatkit打开Whatsapp Web的窗口未被选中。当它打开 Whatsapp Web,等待几秒钟并单击“输入”时,浏览器窗口不会处理“输入”。将以下代码添加到您的程序中:

# Import Libraries
import pywhatkit
import pyautogui
from tkinter import *

win = Tk() # Some Tkinter stuff
screen_width = win.winfo_screenwidth() # Gets the resolution (width) of your monitor
screen_height= win.winfo_screenheight() # Gets the resolution (height) of your monitor

print(screen_width, screen_height) # prints your monitor's resolution

pywhatkit.sendwhatmsg("+91xxxxxxxxxx", "Enter Message", 0, 0) # Sends the message
pyautogui.moveTo(screen_width * 0.694, screen_height* 0.964) # Moves the cursor the the message bar in Whatsapp
pyautogui.click() # Clicks the bar
pyautogui.press('enter') # Sends the message

无论您使用什么屏幕,pyautogui 都会始终发送您的消息,除非 Whatsapp 更新其 UI。如果发生这种情况,请通过 pyautogui 检查消息栏的位置以及获得的任何值,将其除以屏幕的分辨率。这样,它就可以在任何显示器上运行。


0
投票

调试后

sendwhatmsg
函数正在执行以下操作

  1. 使用此查询打开默认浏览器
    web.open(f"https://web.whatsapp.com/send?phone={phone_no}&text={quote(message)}")
  2. 单击此处 pg.click(core.WIDTH / 2, core.HEIGHT / 2)
  3. 然后按 Enter pg.press("enter")

主要问题是这两个变量

core.WIDTH
core.HEIGHT
为您提供屏幕的分辨率,而不是刚刚在浏览器中打开的选项卡的分辨率。因此,如果浏览器选项卡未最大化,您可能最终会点击其他地方。因此,请确保您的浏览器在打开时最大化。


0
投票

即使我试图用 pywhatkit 做同样的事情,但实际上我发现当消息(即字符串)足够长时,它不会自动发送,需要按 Enter 才能发送消息。如果消息只有一行或其他内容,则会自动发送。

这里是您可以尝试的代码,而不是在 sendwhatmsg 函数中写入时间

w.sendwhatmsg_instantly("Phone_number_with_isd_code", "Your message which you want to send")


-4
投票

你可以这样做:

import pywhatkit as kit
kit.sendwhatmsg('+966********','hi from Python Watsapp Bot',10,56)
© www.soinside.com 2019 - 2024. All rights reserved.