import time
import webbrowser as web
import pyautogui as pg
import keyboard as kb
# Open the tab and wait for it to load
web.open(f"https://web.whatsapp.com/")
time.sleep(10)
message = 'Line 1%0aLine 2'
phone_number = '+5563999999999'
# Click on Chrome address bar then wait 1 second and click again to edit
# To find coordinates you can run
# >>> import mouseinfo
# >>> mouseinfo.MouseInfoWindow()
pg.click(1123,62)
time.sleep(1)
pg.click(1123,62)
# Type in the message, press enter, then wait page to load (8 sec) and click
# enter again to send the message
# These times will depend on internet and computer
kb.write('/send?phone=' + str(phone_number) + '&text=' + str(message_alt))
pg.press('enter')
time.sleep(8)
pg.press('enter')
# This last pause is to run this in a loop
time.sleep(2)
2条答案
按热度按时间rsaldnfx1#
pywhatkit的创建者/作者在这里,库使用webbrowser模块在Google上搜索,此时,在同一个选项卡中搜索,您必须手动更新库的源代码。
要做到这一点,请转到Lib\site-packages\pywhatkit\mainfunctions.py并将行号230替换为
web.open(link,new=2)
,设置new=2将在同一选项卡中打开url。我还没有测试过这个,所以我不能保证这会更好,尝试先导入webbrowser模块,然后执行相同的操作,然后更新源代码。shyt4zoc2#
我发现的一个变通方法是修改库中的代码,但实际上我并没有调用库函数。