0

我正在尝试基于 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 这样的浏览器。有没有更好的方法来创建这样的程序?

4

1 回答 1

0

你可以从 Python 开始玩 web.whatsapp.com。我假设您正在尝试使用代码在 WhatsApp 上发送消息。

在 Python 中,您可以像使用移动应用程序一样进行操作

 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

于 2019-12-15T03:04:15.253 回答