Python send_message() 缺少 1 个必需的位置参数:'text'
Python send_message() missing 1 required positional argument: 'text'
我正在编写一个解析器机器人,它通过 whois 服务检查站点的域名。在终端中解析正常并显示信息,但是当需要在聊天中发送此文本时,会生成错误(send_message() 缺少 1 个必需的位置参数:'text')
这只是一个 link 检查:
@bot.message_handler(commands=['getpng'])
def get_screenshot(message):
@bot.message_handler(commands=['getpng'])
def get_screenshot(message):
uid = message.chat.id
url = ""
try:
url = message.text.split(' ')[1]
except IndexError:
bot.send_message(uid, 'You have not entered URL!')
return
if not validators.url(url):
bot.send_message(uid, 'URL is invalid!')
else:
**this is the problematic part of the code:**
browser = webdriver.Chrome()
browser.get('https://www.nic.ru/whois/')
input1 = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[1]/div/div/div/input')
input1.send_keys(url)
time.sleep(2)
button = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[1]/div/button/span[1]')
button.click()
time.sleep(5)
infa = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[4]/div/div[2]/a[1]')
infa1 = infa.text
#print(infa1)
bot.send_message(infa1)
我在 运行 代码时遇到了这个错误。
为什么 infa1 中的文本不可见?我该如何解决?
更新:
Возникло исключение: TypeError (note: full exception trace is shown but execution is paused at: get_screenshot)
send_message() missing 1 required positional argument: 'text'
File "C:\Users\Petyal\Desktop\something.py", line 41, in get_screenshot (Current frame)
bot.send_message(infa1)
File "C:\Users\Petyal\Desktop\something.py", line 56, in <module>
bot.infinity_polling()
我想你错过了 send_message 函数中的 chat_id 参数
尝试添加一个参数:
bot.send_message(chat_id, text)
我正在编写一个解析器机器人,它通过 whois 服务检查站点的域名。在终端中解析正常并显示信息,但是当需要在聊天中发送此文本时,会生成错误(send_message() 缺少 1 个必需的位置参数:'text')
这只是一个 link 检查:
@bot.message_handler(commands=['getpng'])
def get_screenshot(message):
@bot.message_handler(commands=['getpng'])
def get_screenshot(message):
uid = message.chat.id
url = ""
try:
url = message.text.split(' ')[1]
except IndexError:
bot.send_message(uid, 'You have not entered URL!')
return
if not validators.url(url):
bot.send_message(uid, 'URL is invalid!')
else:
**this is the problematic part of the code:**
browser = webdriver.Chrome()
browser.get('https://www.nic.ru/whois/')
input1 = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[1]/div/div/div/input')
input1.send_keys(url)
time.sleep(2)
button = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[1]/div/button/span[1]')
button.click()
time.sleep(5)
infa = browser.find_element_by_xpath('//*[@id="rc-web-client"]/div/div/div[1]/main/div[1]/div[4]/div/div[2]/a[1]')
infa1 = infa.text
#print(infa1)
bot.send_message(infa1)
我在 运行 代码时遇到了这个错误。
为什么 infa1 中的文本不可见?我该如何解决?
更新:
Возникло исключение: TypeError (note: full exception trace is shown but execution is paused at: get_screenshot)
send_message() missing 1 required positional argument: 'text'
File "C:\Users\Petyal\Desktop\something.py", line 41, in get_screenshot (Current frame)
bot.send_message(infa1)
File "C:\Users\Petyal\Desktop\something.py", line 56, in <module>
bot.infinity_polling()
我想你错过了 send_message 函数中的 chat_id 参数
尝试添加一个参数:
bot.send_message(chat_id, text)