My Error is:
web.open("https://web.whatsapp.com/send?phone=" +lead+ "&text=" +message)
TypeError: can only concatenate str (not "float") to str
我正在尝试自动Whatsapp消息,它显示了这个错误。我不明白这是什么意思。
import pyautogui as pg
import webbrowser as web
import time
import pandas as pd
data = pd.read_csv("phone numbers.csv")
data_dict = data.to_dict('list')
leads = data_dict['Number']
messages = data_dict['Message']
combo = zip(leads,messages)
first = True
for lead,message in combo:
time.sleep(4)
web.open("https://web.whatsapp.com/send?phone="+lead+"&text="+message)
if first:
time.sleep(6)
first=False
width,height = pg.size()
pg.click(width/2,height/2)
time.sleep(8)
pg.press('enter')
time.sleep(8)
pg.hotkey('ctrl', 'w')
您需要首先将lead
转换为它的字符串表示:
web.open("https://web.whatsapp.com/send?phone="+str(lead)+"&text="+message)
您看到的错误是因为您的lead
变量是一个数字,或float
类型的变量,而不是string
。
"Concatenate"这就是你在web.open
行代码中试图用+
做的事情——你通过将多个字符串加在一起来生成一个新的字符串。
然而,Python不允许你将数字或其他非字符串类型连接到字符串,除非先显式转换它。
web.open("https://web.whatsapp.com/send?phone="+str(lead)+"&text="+message)