python-3.x 在同一选项卡中使用pywhatkkit而不是使用new

pbwdgjma  于 2022-12-20  发布在  Python
关注(0)|答案(2)|浏览(114)

我想使用pywhatkit在相同的标签页中搜索,而不是在新标签页中打开。我使用以下代码:

import pywhatkit as kit 
kit.search(query)

它在新标签页中打开新搜索查询,而不是使用当前标签页。如果有人知道处理此问题的方法,请帮助。

rsaldnfx

rsaldnfx1#

pywhatkit的创建者/作者在这里,库使用webbrowser模块在Google上搜索,此时,在同一个选项卡中搜索,您必须手动更新库的源代码。
要做到这一点,请转到Lib\site-packages\pywhatkit\mainfunctions.py并将行号230替换为web.open(link,new=2),设置new=2将在同一选项卡中打开url。我还没有测试过这个,所以我不能保证这会更好,尝试先导入webbrowser模块,然后执行相同的操作,然后更新源代码。

shyt4zoc

shyt4zoc2#

我发现的一个变通方法是修改库中的代码,但实际上我并没有调用库函数。

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)

相关问题