使用 Python 发送的 WhatsApp 消息中的换行符 [英] Line breaks in WhatsApp messages sent with Python

查看:61
本文介绍了使用 Python 发送的 WhatsApp 消息中的换行符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个相当简单的代码来通过 Python 发送 WhatsApp 消息,我需要使用换行符.

I am making a fairly simple code to send WhatsApp messages through Python and I need to use line breaks.

例如,如果消息是亲爱的学生,请发送您的报告,谢谢您的关注"

For example, if the message is "Dear Student, Please send your report Thank you for your attention"

WhatsApp 上的消息应该是这样的

The message on WhatsApp should look like

亲爱的同学:

请发送您的报告

感谢您的关注

尝试使用 \n 无效.文本必须在单个消息中.下面是我已经进阶的代码,先谢谢大家的帮助.

Attempts with \ n have not worked. The text must be in a single message. Below the code that I have advanced, thanks in advance for the help.

# Necessary libraries 

import pyautogui as pg
import webbrowser as web
import time    

message = "Dear Student, \n Please send your report\n Thank you for your attention"

number = 'XX_XXXXXXXXX'

web.open("https://web.whatsapp.com/send?phone="+number+"&text="+message)

time.sleep(12) # wait for the page to load

pg.click(1335, 690) # click on the submit button location

推荐答案

消息使用urlencodedtext,因为是http请求,因此,您的信息将是

Use urlencodedtext for the message, because it is a http request, as so, your message would be

Dear%20Student%2C%0APlease%20send%20your%20report%0AThank%20you%20for%20your%20attention

首先检查这个问题

这篇关于使用 Python 发送的 WhatsApp 消息中的换行符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆