我正在尝试基于WhatsApp的Web应用程序创建一个程序。我正在尝试找出哪种语言是启动此类程序的最佳方法。例如,我已经使用Java尝试了此操作,但是使用了以下实现:
public UrlReader() throws IOException {
try {
URL whatsApp = new URL("https://web.whatsapp.com/");
DataInputStream dis = new DataInputStream(whatsApp.openStream());
String inputLine;
while ((inputLine = dis.readLine()) != null) {
System.out.println(inputLine);
}
dis.close();
} catch (MalformedURLException me) {
System.out.println("MalformedURLException: " + me);
} catch (IOException ioe) {
System.out.println("IOException: " + ioe);
}
}
这只是从oracle网站进行的基本复制和粘贴。该程序的输出是一个网站,告诉我必须使用chrome之类的浏览器。有没有更好的方法来创建这样的程序?
答案 0 :(得分:0)
您可以从Python开始使用web.whatsapp.com。我假设您正在尝试使用代码在WhatsApp上发送消息。
在Python中,您可以像使用mobile application
一样进行操作 web.open('https://web.whatsapp.com/send?phone='+phone_no+'&text='+message)
这将预填充给定手机号码的文本(输入phone_no作为CountryCode和号码,例如+918888888888) 然后使用 pyautogui 可以按Enter键进入whatsapp.web
工作代码:
def sendwhatmsg(phone_no, message, time_hour, time_min):
'''Sends whatsapp message to a particulal number at given time'''
if time_hour == 0:
time_hour = 24
callsec = (time_hour*3600)+(time_min*60)
curr = time.localtime()
currhr = curr.tm_hour
currmin = curr.tm_min
currsec = curr.tm_sec
currtotsec = (currhr*3600)+(currmin*60)+(currsec)
lefttm = callsec-currtotsec
if lefttm <= 0:
lefttm = 86400+lefttm
if lefttm < 60:
raise Exception("Call time must be greater than one minute")
else:
sleeptm = lefttm-60
time.sleep(sleeptm)
web.open('https://web.whatsapp.com/send?phone='+phone_no+'&text='+message)
time.sleep(60)
pg.press('enter')
我已从此存储库中提取了此文件-Github repo