我正在撰寫一個決議器機器人,它通過 whois 服務檢查站點的域名。在終端中決議正常并顯示資訊,但是當需要在聊天中發送此文本時,會生成錯誤(send_message() 缺少 1 個必需的位置引數:'text')
這只是一個鏈接檢查:
@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()
uj5u.com熱心網友回復:
我想你錯過了 send_message 函式中的 chat_id 引數
嘗試添加一個引數:
bot.send_message(chat_id, text)
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/324852.html
